use of org.jnosql.diana.mongodb.document.MongoDBUtils.ID_FIELD in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerAsync method update.
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);
}
use of org.jnosql.diana.mongodb.document.MongoDBUtils.ID_FIELD in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManager method update.
@Override
public DocumentEntity update(DocumentEntity entity) {
DocumentEntity copy = entity.copy();
String collectionName = entity.getName();
MongoCollection<Document> collection = mongoDatabase.getCollection(collectionName);
Document id = copy.find(ID_FIELD).map(d -> new Document(d.getName(), d.getValue().get())).orElseThrow(() -> new UnsupportedOperationException("To update this DocumentEntity " + "the field `id` is required"));
copy.remove(ID_FIELD);
collection.findOneAndReplace(id, getDocument(entity));
return entity;
}
Aggregations