Search in sources :

Example 6 with ReturnDocument

use of com.mongodb.client.model.ReturnDocument in project mongo-java-driver by mongodb.

the class FindAndReplaceAcceptanceTest method shouldReturnNewDocumentAfterReplaceWhenUsingReplaceOneAndGet.

@Test
public void shouldReturnNewDocumentAfterReplaceWhenUsingReplaceOneAndGet() {
    ObjectId id = new ObjectId();
    Document documentInserted = new Document("_id", id).append(KEY, VALUE_TO_CARE_ABOUT);
    Document documentReplacement = new Document("_id", id).append("foo", "bar");
    collection.insertOne(documentInserted);
    assertThat(collection.count(), is(1L));
    Document document = collection.findOneAndReplace(new Document(KEY, VALUE_TO_CARE_ABOUT), documentReplacement, new FindOneAndReplaceOptions().returnDocument(ReturnDocument.AFTER));
    assertThat("Document, retrieved from replaceAndGet after change applied should match the document used as replacement", document, equalTo(documentReplacement));
}
Also used : FindOneAndReplaceOptions(com.mongodb.client.model.FindOneAndReplaceOptions) ObjectId(org.bson.types.ObjectId) Document(org.bson.Document) ReturnDocument(com.mongodb.client.model.ReturnDocument) Test(org.junit.Test)

Aggregations

ReturnDocument (com.mongodb.client.model.ReturnDocument)6 Document (org.bson.Document)6 Test (org.junit.Test)6 ObjectId (org.bson.types.ObjectId)4 FindOneAndReplaceOptions (com.mongodb.client.model.FindOneAndReplaceOptions)3 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)3 Worker (com.mongodb.client.test.Worker)2 WorkerCodecProvider (com.mongodb.client.test.WorkerCodecProvider)2 Date (java.util.Date)2 BsonValueCodecProvider (org.bson.codecs.BsonValueCodecProvider)2 DocumentCodecProvider (org.bson.codecs.DocumentCodecProvider)2 ValueCodecProvider (org.bson.codecs.ValueCodecProvider)2 CodecRegistry (org.bson.codecs.configuration.CodecRegistry)2