如何运行具有匹配和投影的聚合。投影包括一个字段并排除 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();
1 回答

汪汪一只猫
TA贡献1898条经验 获得超8个赞
Aggregation aggregation = Aggregation.newAggregation( Aggregation.match(Criteria.where("someCriteriaFlag").is(false)), Aggregation.project("field1").andExclude("_id")); List<String> fields= mongoTemplate.aggregate(aggregation, "Collection", BasicDBObject.class) .getMappedResults();
添加回答
举报
0/150
提交
取消