本文整理了Java中org.springframework.data.mongodb.core.query.Criteria.elemMatch()
方法的一些代码示例,展示了Criteria.elemMatch()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Criteria.elemMatch()
方法的具体详情如下:
包路径:org.springframework.data.mongodb.core.query.Criteria
类名称:Criteria
方法名:elemMatch
[英]Creates a criterion using the $elemMatch operator
[中]使用$elemMatch运算符创建条件
代码示例来源:origin: com.epam.reportportal/commons-dao
@Override
public List<UserFilter> findAvailableFilters(String projectName, String[] ids, String userName) {
//where ID from provided array AND it's shared on project
Query q = Query.query(where(ID).in(Arrays.asList(ids))
.andOperator(new Criteria()
.orOperator(
where(OWNER).is(userName),
where(PROJECT).is(projectName),
where(ENTRIES).elemMatch(where("projectId").is(projectName)))));
return mongoTemplate.find(q, UserFilter.class);
}
}
代码示例来源:origin: com.github.rutledgepaulv/q-builders
@Override
protected Criteria visit(ComparisonNode node) {
ComparisonOperator operator = node.getOperator();
Collection<?> values = node.getValues().stream().map(normalizer).collect(Collectors.toList());
String field = node.getField().asKey();
if(ComparisonOperator.EQ.equals(operator)) {
return where(field).is(single(values));
} else if(ComparisonOperator.NE.equals(operator)) {
return where(field).ne(single(values));
} else if (ComparisonOperator.EX.equals(operator)) {
return where(field).exists((Boolean)single(values));
} else if (ComparisonOperator.GT.equals(operator)) {
return where(field).gt(single(values));
} else if (ComparisonOperator.LT.equals(operator)) {
return where(field).lt(single(values));
} else if (ComparisonOperator.GTE.equals(operator)) {
return where(field).gte(single(values));
} else if (ComparisonOperator.LTE.equals(operator)) {
return where(field).lte(single(values));
} else if (ComparisonOperator.IN.equals(operator)) {
return where(field).in(values);
} else if (ComparisonOperator.NIN.equals(operator)) {
return where(field).nin(values);
} else if (ComparisonOperator.RE.equals(operator)) {
return where(field).regex((String)single(values));
} else if (ComparisonOperator.SUB_CONDITION_ANY.equals(operator)) {
return where(field).elemMatch(condition(node));
}
throw new UnsupportedOperationException("This visitor does not support the operator " + operator + ".");
}
代码示例来源:origin: com.bq.oss.lib/queries-mongo
private Criteria criteria(QueryOperator operator, String field, QueryLiteral<?> value) {
Criteria criteria = new Criteria(field);
switch (operator) {
case $ALL:
return criteria.all(((ListQueryLiteral) value).getLiterals());
case $EQ:
return criteria.is(value.getLiteral());
case $GT:
return criteria.gt(value.getLiteral());
case $GTE:
return criteria.gte(value.getLiteral());
case $IN:
return criteria.in(((ListQueryLiteral) value).getLiterals());
case $NIN:
return criteria.nin(((ListQueryLiteral) value).getLiterals());
case $LT:
return criteria.lt(value.getLiteral());
case $LTE:
return criteria.lte(value.getLiteral());
case $NE:
return criteria.ne(value.getLiteral());
case $LIKE:
return criteria.regex((String) value.getLiteral(), "i"); // i means case insensitive
case $ELEM_MATCH:
return criteria.elemMatch(getCriteriaFromResourceQuery((ResourceQuery) value.getLiteral()));
case $EXISTS:
return criteria.exists((Boolean) value.getLiteral());
}
return criteria;
}
内容来源于网络,如有侵权,请联系作者删除!