use of com.mongodb.async.client.MongoCollection in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerAsync method select.
@Override
public void select(DocumentQuery query, Consumer<List<DocumentEntity>> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
String collectionName = query.getDocumentCollection();
MongoCollection<Document> collection = asyncMongoDatabase.getCollection(collectionName);
Bson mongoDBQuery = query.getCondition().map(DocumentQueryConversor::convert).orElse(EMPTY);
List<DocumentEntity> entities = new CopyOnWriteArrayList<>();
FindIterable<Document> result = collection.find(mongoDBQuery);
Block<Document> documentBlock = d -> entities.add(createEntity(collectionName, d));
SingleResultCallback<Void> voidSingleResultCallback = (v, e) -> callBack.accept(entities);
result.forEach(documentBlock, voidSingleResultCallback);
}
Aggregations