MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

Esegui MongoTemplate.aggregate senza recuperare le righe

Usa AggregationOption - skipOutput() . Questo non restituirà un risultato nel caso in cui la pipeline di aggregazione contenga un'operazione $out/$merge.

mongoTemplate.aggregate(aggregation.withOptions(newAggregationOptions().skipOutput().allowDiskUse(true).build()), "collectionNme", EntityClass.class);

Se stai usando MongoDriver senza framework.

MongoClient client = MongoClients.create("mongodb://localhost:27017");
 MongoDatabase database = client.getDatabase("my-collection");
 MongoCollection<Document> model = database.getCollection(collectionName);
 AggregateIterable<Document> aggregateResult = model.aggregate(bsonListOfAggregationPipeline);
 
 // instead iterating over call toCollection() to skipResult
 aggregateIterable.toCollection();

Riferimenti: