com.mongodb.client.model.Filters.not()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(105)

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

Filters.not介绍

[英]Creates a filter that matches all documents that do not match the passed in filter. Requires the field name to passed as part of the value passed in and lifts it to create a valid "$not" query:

not(eq("x", 1))

will generate a MongoDB query like:

{x : $not: {$eq : 1}}

[中]创建一个筛选器,该筛选器匹配与传入筛选器不匹配的所有文档。要求将字段名作为传入的值的一部分传递,并将其提升以创建有效的“$not”查询:

not(eq("x", 1))

将生成类似以下内容的MongoDB查询:

{x : $not: {$eq : 1}}

代码示例

代码示例来源:origin: Graylog2/graylog2-server

@Override
  public void upgrade() {
    final FindIterable<Document> documentsWithMissingFields = collection.find(or(not(exists(ContentPack.FIELD_META_ID)), not(exists(ContentPack.FIELD_META_REVISION))));
    for (Document document : documentsWithMissingFields) {
      final ObjectId objectId = document.getObjectId("_id");
      LOG.debug("Found document with missing \"id\" or \"rev\" field with ID <{}>", objectId);
      final String id = document.get("id", objectId.toHexString());
      final int rev = document.get("rev", 0);

      document.put("id", id);
      document.put("rev", rev);

      final UpdateResult updateResult = collection.replaceOne(eq("_id", objectId), document);

      if (updateResult.wasAcknowledged()) {
        LOG.debug("Successfully updated document with ID <{}>", objectId);
      } else {
        LOG.error("Failed to update document with ID <{}>", objectId);
      }
    }
  }
}

代码示例来源:origin: eclipse/ditto

/**
 * Creates a visitor to create policy-restriction Bson objects.
 *
 * @param authorizationSubjectsPredicate the predicate returning the "subject ids" of the search request.
 */
private CreatePolicyRestrictionBsonVisitor(final Predicate authorizationSubjectsPredicate) {
  grantedBson = CreateBsonPredicateVisitor.apply(authorizationSubjectsPredicate, PersistenceConstants.FIELD_GRANTS_GRANTED);
  notRevokedBson =
      Filters.not(CreateBsonPredicateVisitor.apply(authorizationSubjectsPredicate, PersistenceConstants.FIELD_GRANTS_REVOKED));
}

代码示例来源:origin: ch.exense.step/core

@Override
public Bson visitNotExpr(NotExprContext ctx) {
  return not(this.visit(ctx.expr()));
}

代码示例来源:origin: org.eclipse.ditto/ditto-services-thingsearch-persistence

/**
 * Creates a visitor to create policy-restriction Bson objects.
 *
 * @param authorizationSubjectsPredicate the predicate returning the "subject ids" of the search request.
 */
private CreatePolicyRestrictionBsonVisitor(final Predicate authorizationSubjectsPredicate) {
  grantedBson = CreateBsonPredicateVisitor.apply(authorizationSubjectsPredicate, PersistenceConstants.FIELD_GRANTS_GRANTED);
  notRevokedBson =
      Filters.not(CreateBsonPredicateVisitor.apply(authorizationSubjectsPredicate, PersistenceConstants.FIELD_GRANTS_REVOKED));
}

代码示例来源:origin: com.holon-platform.mongo/holon-datastore-mongo-core

@Override
public BsonFilterExpression visit(NotFilter filter, MongoResolutionContext<?> context) {
  final BsonFilterExpression toNegate = context.resolveOrFail(filter.getComposition().get(0),
      BsonFilterExpression.class);
  return toNegate.getPipeline()
      .map(pipeline -> BsonFilterExpression.create(Filters.not(pipeline.getMatch()),
          pipeline.getProjection().orElse(null)))
      .orElse(BsonFilterExpression.create(Filters.not(toNegate.getExpression())));
}

代码示例来源:origin: epam/DLab

private Bson computationalFilter(String user, String exploratoryName, String computationalStatus, String
    computationalImage, UserInstanceStatus[] excludedStatuses) {
  final String[] statuses = Arrays.stream(excludedStatuses)
      .map(UserInstanceStatus::toString)
      .toArray(String[]::new);
  return and(exploratoryCondition(user, exploratoryName),
      elemMatch(COMPUTATIONAL_RESOURCES, and(eq(IMAGE, computationalImage),
          not(in(STATUS, statuses)),
          not(eq(STATUS, computationalStatus)))));
}

代码示例来源:origin: com.holon-platform.mongo/holon-datastore-mongo-core

@Override
public BsonFilterExpression visit(NullFilter filter, MongoResolutionContext<?> context) {
  // not exists or it is not null
  return resolveFieldName(filter.getLeftOperand(), context)
      .map(fn -> Filters.or(Filters.not(Filters.exists(fn)), Filters.type(fn, BsonType.NULL)))
      .map(bson -> BsonFilterExpression.create(bson)).orElse(null);
}

代码示例来源:origin: com.holon-platform.mongo/holon-datastore-mongo-core

@Override
public BsonFilterExpression visit(NotNullFilter filter, MongoResolutionContext<?> context) {
  // exists and it is not null
  return resolveFieldName(filter.getLeftOperand(), context)
      .map(fn -> Filters.and(Filters.exists(fn), Filters.not(Filters.type(fn, BsonType.NULL))))
      .map(bson -> BsonFilterExpression.create(bson)).orElse(null);
}

代码示例来源:origin: labsai/EDDI

@Override
public Long getActiveConversationCount(String botId, Integer botVersion) {
  Bson query = Filters.and(Filters.eq("botId", botId), Filters.eq("botVersion", botVersion),
      Filters.not(new Document("conversationState", ENDED.toString())));
  return conversationCollection.countDocuments(query);
}

代码示例来源:origin: epam/DLab

public boolean edgeNodeExist(String user) {
  return findOne(USER_EDGE, and(eq(ID, user), not(in(EDGE_STATUS, UserInstanceStatus.TERMINATING.toString(),
      UserInstanceStatus.TERMINATED.toString()))))
      .isPresent();
}

代码示例来源:origin: io.gravitee.repository/gravitee-repository-mongodb

private Bson getQueryFindMedia(String hash, String api, String mediaType) {
  Bson addQuery = api == null ? not(exists("metadata.api")) : eq("metadata.api", api);
  return and(eq("metadata.type", mediaType), eq("metadata.hash", hash), addQuery);
}

代码示例来源:origin: epam/DLab

/**
 * Finds and returns the info of all user's notebooks whose status is absent among predefined ones.
 *
 * @param user     user name.
 * @param statuses array of statuses.
 */
public List<UserInstanceDTO> fetchUserExploratoriesWhereStatusNotIn(String user, UserInstanceStatus... statuses) {
  final List<String> statusList = statusList(statuses);
  return getUserInstances(
      and(
          eq(USER, user),
          not(in(STATUS, statusList))
      ),
      false);
}

代码示例来源:origin: com.holon-platform.mongo/holon-datastore-mongo-core

Filters.not(Filters.type(countByField, BsonType.NULL)))));
if (!query.getDefinition().isDistinct()) {

代码示例来源:origin: epam/DLab

/**
 * Updates the status of exploratory notebooks in Mongo database.
 *
 * @param dto object of exploratory status info.
 * @return The result of an update operation.
 */
public int updateComputationalStatusesForExploratory(StatusEnvBaseDTO<?> dto) {
  Document values = new Document(computationalFieldFilter(STATUS), dto.getStatus());
  values.append(computationalFieldFilter(UPTIME), null);
  int count = 0;
  UpdateResult result;
  do {
    result = updateOne(USER_INSTANCES,
        and(exploratoryCondition(dto.getUser(), dto.getExploratoryName()),
            elemMatch(COMPUTATIONAL_RESOURCES,
                and(not(eq(STATUS, TERMINATED.toString())),
                    not(eq(STATUS, dto.getStatus()))))),
        new Document(SET, values));
    count += result.getModifiedCount();
  }
  while (result.getModifiedCount() > 0);
  return count;
}

代码示例来源:origin: epam/DLab

and(eq(ComputationalDAO.COMPUTATIONAL_NAME, computationalName),
            eq(COMPUTATIONAL_SPOT, true),
            not(eq(STATUS, TERMINATED.toString())))),
        include(COMPUTATIONAL_RESOURCES + "." + COMPUTATIONAL_SPOT))
).orElse(null);

代码示例来源:origin: epam/DLab

/**
 * Updates the status of computational resource in Mongo database.
 *
 * @param dto object of computational resource status.
 * @return The result of an update operation.
 */
public UpdateResult updateComputationalStatus(ComputationalStatusDTO dto) {
  try {
    Document values = new Document(computationalFieldFilter(STATUS), dto.getStatus());
    return updateOne(USER_INSTANCES,
        and(exploratoryCondition(dto.getUser(), dto.getExploratoryName()),
            elemMatch(COMPUTATIONAL_RESOURCES,
                and(eq(COMPUTATIONAL_NAME, dto.getComputationalName()),
                    not(eq(STATUS, TERMINATED.toString()))))),
        new Document(SET, values));
  } catch (Exception t) {
    throw new DlabException("Could not update computational resource status", t);
  }
}

代码示例来源:origin: epam/DLab

elemMatch(COMPUTATIONAL_RESOURCES,
          and(eq(COMPUTATIONAL_NAME, dto.getComputationalName()),
              not(eq(STATUS, TERMINATED.toString()))))),
      new Document(SET, values));
} catch (Exception t) {

相关文章