Example usage for com.mongodb.async.client MongoCollection findOneAndReplace

List of usage examples for com.mongodb.async.client MongoCollection findOneAndReplace

Introduction

In this page you can find the example usage for com.mongodb.async.client MongoCollection findOneAndReplace.

Prototype

void findOneAndReplace(Bson filter, TDocument replacement, SingleResultCallback<TDocument> callback);

Source Link

Document

Atomically find a document and replace it.

Usage

From source file:org.jnosql.diana.mongodb.document.MongoDBDocumentCollectionManagerAsync.java

License:Open Source License

private void update(DocumentEntity entity, SingleResultCallback<Document> callBack) {
    String collectionName = entity.getName();
    com.mongodb.async.client.MongoCollection<Document> asyncCollection = asyncMongoDatabase
            .getCollection(collectionName);
    Document id = entity.find(ID_FIELD).map(d -> new Document(d.getName(), d.getValue().get()))
            .orElseThrow(() -> new UnsupportedOperationException(
                    "To update this DocumentEntity " + "the field `id` is required"));

    asyncCollection.findOneAndReplace(id, getDocument(entity), callBack);
}