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));
}
Aggregations