org.springframework.data.mongodb.core.query.Criteria.nin()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(3.7k)|赞(0)|评价(0)|浏览(308)

本文整理了Java中org.springframework.data.mongodb.core.query.Criteria.nin()方法的一些代码示例,展示了Criteria.nin()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Criteria.nin()方法的具体详情如下:
包路径:org.springframework.data.mongodb.core.query.Criteria
类名称:Criteria
方法名:nin

Criteria.nin介绍

[英]Creates a criterion using the $nin operator.
[中]使用$nin运算符创建条件。

代码示例

代码示例来源:origin: spring-projects/spring-data-mongodb

/**
 * Creates a criterion using the {@literal $nin} operator.
 *
 * @param o
 * @return
 * @see <a href="https://docs.mongodb.com/manual/reference/operator/query/nin/">MongoDB Query operator: $nin</a>
 */
public Criteria nin(Object... o) {
  return nin(Arrays.asList(o));
}

代码示例来源:origin: spring-projects/spring-data-mongodb

return criteria.is(null);
case NOT_IN:
  return criteria.nin(nextAsArray(parameters));
case IN:
  return criteria.in(nextAsArray(parameters));

代码示例来源:origin: org.springframework.data/spring-data-mongodb

/**
 * Creates a criterion using the {@literal $nin} operator.
 *
 * @param o
 * @return
 * @see <a href="https://docs.mongodb.com/manual/reference/operator/query/nin/">MongoDB Query operator: $nin</a>
 */
public Criteria nin(Object... o) {
  return nin(Arrays.asList(o));
}

代码示例来源:origin: org.springframework.data/spring-data-mongodb

return criteria.is(null);
case NOT_IN:
  return criteria.nin(nextAsArray(parameters));
case IN:
  return criteria.in(nextAsArray(parameters));

代码示例来源: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;
}

相关文章