private boolean getUpdatedExisting(final BulkWriteResult bulkWriteResult) { if (getType() == UPDATE) { return bulkWriteResult.getMatchedCount() > 0; } return false; }
private int getCount(final BulkWriteResult bulkWriteResult) { int count = 0; if (getType() == UPDATE || getType() == REPLACE) { count = bulkWriteResult.getMatchedCount() + bulkWriteResult.getUpserts().size(); } else if (getType() == DELETE) { count = bulkWriteResult.getDeletedCount(); } return count; }
private WriteConcernResult translateBulkWriteResult(final WriteRequest.Type type, final BulkWriteResult writeResult) { switch (type) { case INSERT: return WriteConcernResult.acknowledged(writeResult.getInsertedCount(), false, null); case DELETE: return WriteConcernResult.acknowledged(writeResult.getDeletedCount(), false, null); case UPDATE: case REPLACE: return WriteConcernResult.acknowledged(writeResult.getMatchedCount() + writeResult.getUpserts().size(), writeResult.getMatchedCount() > 0, writeResult.getUpserts().isEmpty() ? null : writeResult.getUpserts().get(0).getId()); default: throw new MongoInternalException("Unhandled write request type: " + type); } }
private UpdateResult toUpdateResult(final com.mongodb.bulk.BulkWriteResult result) { if (result.wasAcknowledged()) { Long modifiedCount = result.isModifiedCountAvailable() ? (long) result.getModifiedCount() : null; BsonValue upsertedId = result.getUpserts().isEmpty() ? null : result.getUpserts().get(0).getId(); return UpdateResult.acknowledged(result.getMatchedCount(), modifiedCount, upsertedId); } else { return UpdateResult.unacknowledged(); } }
return false; if (matchedCount != that.getMatchedCount()) { return false;
/** * Add a result * * @param result the result * @param indexMap the index map */ public void addResult(final BulkWriteResult result, final IndexMap indexMap) { insertedCount += result.getInsertedCount(); matchedCount += result.getMatchedCount(); deletedCount += result.getDeletedCount(); if (result.isModifiedCountAvailable() && modifiedCount != null) { modifiedCount += result.getModifiedCount(); } else { modifiedCount = null; } mergeUpserts(result.getUpserts(), indexMap); }
static BulkWriteResult translateBulkWriteResult(final com.mongodb.bulk.BulkWriteResult bulkWriteResult, final Decoder<DBObject> decoder) { if (bulkWriteResult.wasAcknowledged()) { Integer modifiedCount = (bulkWriteResult.isModifiedCountAvailable()) ? bulkWriteResult.getModifiedCount() : null; return new AcknowledgedBulkWriteResult(bulkWriteResult.getInsertedCount(), bulkWriteResult.getMatchedCount(), bulkWriteResult.getDeletedCount(), modifiedCount, translateBulkWriteUpserts(bulkWriteResult.getUpserts(), decoder)); } else { return new UnacknowledgedBulkWriteResult(); } }
private void addBulkWriteResultToResponse(final BulkWriteResult bulkWriteResult, final BsonDocument response) { response.put("ok", new BsonInt32(1)); if (getType() == INSERT) { response.put("n", new BsonInt32(0)); } else if (getType() == DELETE) { response.put("n", new BsonInt32(bulkWriteResult.getDeletedCount())); } else if (getType() == UPDATE || getType() == REPLACE) { response.put("n", new BsonInt32(bulkWriteResult.getMatchedCount() + bulkWriteResult.getUpserts().size())); if (bulkWriteResult.getUpserts().isEmpty()) { response.put("updatedExisting", BsonBoolean.TRUE); } else { response.put("updatedExisting", BsonBoolean.FALSE); response.put("upserted", bulkWriteResult.getUpserts().get(0).getId()); } } }
private boolean getUpdatedExisting(final BulkWriteResult bulkWriteResult) { if (getType() == UPDATE) { return bulkWriteResult.getMatchedCount() > 0; } return false; }
private void insertUpdateInBulkNoMatch(boolean ordered) { collection.insertOne(json("foo: 'bar'")); List<WriteModel<Document>> ops = new ArrayList<>(); ops.add(new UpdateOneModel<Document>(ne("foo", "bar"), set("field", "y"))); BulkWriteResult result = collection.bulkWrite(ops, new BulkWriteOptions().ordered(ordered)); assertThat(result.getInsertedCount()).isEqualTo(0); assertThat(result.getDeletedCount()).isEqualTo(0); assertThat(result.getModifiedCount()).isEqualTo(0); assertThat(result.getMatchedCount()).isEqualTo(0); }
private int getCount(final BulkWriteResult bulkWriteResult) { int count = 0; if (getType() == UPDATE || getType() == REPLACE) { count = bulkWriteResult.getMatchedCount() + bulkWriteResult.getUpserts().size(); } else if (getType() == DELETE) { count = bulkWriteResult.getDeletedCount(); } return count; }
private WriteConcernResult translateBulkWriteResult(final WriteRequest.Type type, final BulkWriteResult writeResult) { switch (type) { case INSERT: return WriteConcernResult.acknowledged(writeResult.getInsertedCount(), false, null); case DELETE: return WriteConcernResult.acknowledged(writeResult.getDeletedCount(), false, null); case UPDATE: case REPLACE: return WriteConcernResult.acknowledged(writeResult.getMatchedCount() + writeResult.getUpserts().size(), writeResult.getMatchedCount() > 0, writeResult.getUpserts().isEmpty() ? null : writeResult.getUpserts().get(0).getId()); default: throw new MongoInternalException("Unhandled write request type: " + type); } }
private WriteConcernResult translateBulkWriteResult(final WriteRequest.Type type, final BulkWriteResult writeResult) { switch (type) { case INSERT: return WriteConcernResult.acknowledged(writeResult.getInsertedCount(), false, null); case DELETE: return WriteConcernResult.acknowledged(writeResult.getDeletedCount(), false, null); case UPDATE: case REPLACE: return WriteConcernResult.acknowledged(writeResult.getMatchedCount() + writeResult.getUpserts().size(), writeResult.getMatchedCount() > 0, writeResult.getUpserts().isEmpty() ? null : writeResult.getUpserts().get(0).getId()); default: throw new MongoInternalException("Unhandled write request type: " + type); } }
private UpdateResult toUpdateResult(final com.mongodb.bulk.BulkWriteResult result) { if (result.wasAcknowledged()) { Long modifiedCount = result.isModifiedCountAvailable() ? (long) result.getModifiedCount() : null; BsonValue upsertedId = result.getUpserts().isEmpty() ? null : result.getUpserts().get(0).getId(); return UpdateResult.acknowledged(result.getMatchedCount(), modifiedCount, upsertedId); } else { return UpdateResult.unacknowledged(); } }
private UpdateResult toUpdateResult(final com.mongodb.bulk.BulkWriteResult result) { if (result.wasAcknowledged()) { Long modifiedCount = result.isModifiedCountAvailable() ? (long) result.getModifiedCount() : null; BsonValue upsertedId = result.getUpserts().isEmpty() ? null : result.getUpserts().get(0).getId(); return UpdateResult.acknowledged(result.getMatchedCount(), modifiedCount, upsertedId); } else { return UpdateResult.unacknowledged(); } }
private void updateStage(MongoDBOperations mongoDBOps) { MongoDBOperations.StageSecondaryAlternates alternates = mongoDBOps.getSecondaryAlternates(); if (!alternates.getQueries().isEmpty()) { QueryResult<BulkWriteResult> update = stageCollection.update(alternates.getQueries(), alternates.getUpdates(), null); if (update.first().getMatchedCount() != alternates.getQueries().size()) { onUpdateError("populate secondary alternates", update, alternates.getQueries(), alternates.getIds(), stageCollection); } } long cleanDocuments = 0; if (cleanWhileLoading) { cleanDocuments = cleanStage(mongoDBOps); } }
static BulkWriteResult translateBulkWriteResult(final com.mongodb.bulk.BulkWriteResult bulkWriteResult, final Decoder<DBObject> decoder) { if (bulkWriteResult.wasAcknowledged()) { Integer modifiedCount = (bulkWriteResult.isModifiedCountAvailable()) ? bulkWriteResult.getModifiedCount() : null; return new AcknowledgedBulkWriteResult(bulkWriteResult.getInsertedCount(), bulkWriteResult.getMatchedCount(), bulkWriteResult.getDeletedCount(), modifiedCount, translateBulkWriteUpserts(bulkWriteResult.getUpserts(), decoder)); } else { return new UnacknowledgedBulkWriteResult(); } }
private void addBulkWriteResultToResponse(final BulkWriteResult bulkWriteResult, final BsonDocument response) { response.put("ok", new BsonInt32(1)); if (getType() == INSERT) { response.put("n", new BsonInt32(0)); } else if (getType() == DELETE) { response.put("n", new BsonInt32(bulkWriteResult.getDeletedCount())); } else if (getType() == UPDATE || getType() == REPLACE) { response.put("n", new BsonInt32(bulkWriteResult.getMatchedCount() + bulkWriteResult.getUpserts().size())); if (bulkWriteResult.getUpserts().isEmpty()) { response.put("updatedExisting", BsonBoolean.TRUE); } else { response.put("updatedExisting", BsonBoolean.FALSE); response.put("upserted", bulkWriteResult.getUpserts().get(0).getId()); } } }
private Function<BulkWriteResult, Source<Boolean, NotUsed>> mapPolicyUpdateResult(final PolicyUpdate policyUpdate) { final BulkWriteOptions writeOrdered = new BulkWriteOptions(); writeOrdered.ordered(true); return result -> { if (result.getMatchedCount() > 0) { final List<WriteModel<Document>> writePolicyIndexModels = createPolicyIndexModels(policyUpdate.getPolicyIndexRemoveFilter(), policyUpdate.getPolicyIndexInsertEntries()); return Source.fromPublisher( policiesCollection.bulkWrite(writePolicyIndexModels, writeOrdered)) .map(result2 -> Boolean.TRUE); } else { return Source.single(Boolean.FALSE); } }; }
private Function<BulkWriteResult, Source<Boolean, NotUsed>> mapPolicyUpdateResult(final PolicyUpdate policyUpdate) { final BulkWriteOptions writeOrdered = new BulkWriteOptions(); writeOrdered.ordered(true); return result -> { if (result.getMatchedCount() > 0) { final List<WriteModel<Document>> writePolicyIndexModels = createPolicyIndexModels(policyUpdate.getPolicyIndexRemoveFilter(), policyUpdate.getPolicyIndexInsertEntries()); return Source.fromPublisher( policiesCollection.bulkWrite(writePolicyIndexModels, writeOrdered)) .map(result2 -> Boolean.TRUE); } else { return Source.single(Boolean.FALSE); } }; }