Java Code Examples for com.mongodb.bulk.BulkWriteResult#getDeletedCount()

The following examples show how to use com.mongodb.bulk.BulkWriteResult#getDeletedCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoCollectionImpl.java    From core-ng-project with Apache License 2.0 6 votes vote down vote up
@Override
public long bulkDelete(List<?> ids) {
    var watch = new StopWatch();
    int size = ids.size();
    int deletedRows = 0;
    try {
        List<DeleteOneModel<T>> models = new ArrayList<>(size);
        for (Object id : ids) {
            models.add(new DeleteOneModel<>(Filters.eq("_id", id)));
        }
        BulkWriteResult result = collection().bulkWrite(models, new BulkWriteOptions().ordered(false));
        deletedRows = result.getDeletedCount();
        return deletedRows;
    } finally {
        long elapsed = watch.elapsed();
        ActionLogContext.track("mongo", elapsed, 0, deletedRows);
        logger.debug("bulkDelete, collection={}, ids={}, size={}, deletedRows={}, elapsed={}", collectionName, ids, size, deletedRows, elapsed);
        checkSlowOperation(elapsed);
    }
}
 
Example 2
Source File: Utils.java    From vertx-mongo-client with Apache License 2.0 6 votes vote down vote up
static MongoClientBulkWriteResult toMongoClientBulkWriteResult(BulkWriteResult bulkWriteResult) {
  if (!bulkWriteResult.wasAcknowledged()) {
    return null;
  }

  List<JsonObject> upsertResult = bulkWriteResult.getUpserts().stream().map(upsert -> {
    JsonObject upsertValue = convertUpsertId(upsert.getId());
    upsertValue.put(MongoClientBulkWriteResult.INDEX, upsert.getIndex());
    return upsertValue;
  }).collect(Collectors.toList());

  return new MongoClientBulkWriteResult(
    bulkWriteResult.getInsertedCount(),
    bulkWriteResult.getMatchedCount(),
    bulkWriteResult.getDeletedCount(),
    bulkWriteResult.getModifiedCount(),
    upsertResult
  );
}
 
Example 3
Source File: MongoDB.java    From aion with MIT License 5 votes vote down vote up
/**
 * Creates a new instance of the WriteBatchResult from Mongo's raw BulkWriteResult
 *
 * @param writeResult The BulkWriteResult returned from Mongo
 */
public WriteBatchResult(BulkWriteResult writeResult) {
    this.totalUpdates =
            writeResult.getInsertedCount()
                    + writeResult.getModifiedCount()
                    + writeResult.getUpserts().size();
    this.totalDeletes = writeResult.getDeletedCount();
    this.isReadOnly = false;
}