如何运行具有匹配和投影的聚合。投影包括一个字段并排除 id。
db.collection("Collection").aggregate([
{
$match : {
"someCriteriaFlag" : false
}
},
{
$project : {
"field1" : 1,
"_id" : 0
}
}
]);
在爪哇
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.match(Criteria.where("someCriteriaFlag").is(false)),
Aggregation.project("field1"));
List<String> fields= mongoTemplate.aggregate(aggregation, "Collection", BasicDBObject.class)
.getMappedResults();
汪汪一只猫
相关分类