use of com.mongodb.client.model.UpdateOptions in project zeppelin by apache.
the class MongoNotebookRepo method save.
@Override
public void save(Note note, AuthenticationInfo subject) throws IOException {
Document doc = noteToDocument(note);
coll.replaceOne(eq("_id", note.getId()), doc, new UpdateOptions().upsert(true));
}
use of com.mongodb.client.model.UpdateOptions in project mongo-java-driver by mongodb.
the class CrudTest method getUpdateOneMongoOperation.
private MongoOperationUpdateResult getUpdateOneMongoOperation(final BsonDocument arguments) {
return new MongoOperationUpdateResult() {
@Override
public void execute() {
UpdateOptions options = new UpdateOptions();
if (arguments.containsKey("upsert")) {
options.upsert(arguments.getBoolean("upsert").getValue());
}
if (arguments.containsKey("collation")) {
options.collation(getCollation(arguments.getDocument("collation")));
}
collection.updateOne(arguments.getDocument("filter"), arguments.getDocument("update"), options, getCallback());
}
};
}
use of com.mongodb.client.model.UpdateOptions in project mongo-java-driver by mongodb.
the class ReplaceAcceptanceTest method shouldReplaceTheDocumentIfReplacingWithUpsertAndDocumentIsFoundInCollection.
@Test
public void shouldReplaceTheDocumentIfReplacingWithUpsertAndDocumentIsFoundInCollection() {
// given
Document originalDocument = new Document("_id", 3).append("x", 2);
collection.replaceOne(new Document(), originalDocument, new UpdateOptions().upsert(true));
assertThat(collection.count(), is(1L));
// when
Document replacement = originalDocument.append("y", 5);
collection.replaceOne(new Document(), replacement, new UpdateOptions().upsert(true));
// then
assertThat(collection.count(), is(1L));
assertThat(collection.find(new Document("_id", 3)).iterator().next(), is(replacement));
}
use of com.mongodb.client.model.UpdateOptions in project mongo-java-driver by mongodb.
the class UpdateAcceptanceTest method shouldInsertTheDocumentIfUpdatingOneWithUpsertAndDocumentNotFoundInCollection.
@Test
public void shouldInsertTheDocumentIfUpdatingOneWithUpsertAndDocumentNotFoundInCollection() {
// given
Document originalDocument = new Document("_id", 1).append("x", 2);
collection.insertOne(originalDocument);
// when
Document filter = new Document("_id", 2);
collection.updateOne(filter, new Document("$set", new Document("x", 5)), new UpdateOptions().upsert(true));
// then
assertThat(collection.count(), is(2L));
Document expectedDocument = new Document("_id", 2).append("x", 5);
assertThat(collection.find(filter).iterator().next(), is(expectedDocument));
}
use of com.mongodb.client.model.UpdateOptions in project mongo-java-driver by mongodb.
the class UpdateAcceptanceTest method shouldUpdateAllDocumentsIfUpdatingAllWithUpsertAndMultipleDocumentsFoundInCollection.
@Test
public void shouldUpdateAllDocumentsIfUpdatingAllWithUpsertAndMultipleDocumentsFoundInCollection() {
// given
Document firstDocument = new Document("_id", 1).append("x", 3);
collection.insertOne(firstDocument);
Document secondDocument = new Document("_id", 2).append("x", 3);
collection.insertOne(secondDocument);
// when
Document filter = new Document("x", 3);
collection.updateMany(filter, new Document("$set", new Document("x", 5)), new UpdateOptions().upsert(true));
// then
assertThat(collection.count(new Document("x", 5), new CountOptions()), is(2L));
}
Aggregations