mongoTemplate聚合匹配和投影一个没有id的字段
mongTemplate aggregate match and projection one field without id
如何 运行 聚合匹配和投影。投影包括一个字段,不包括id。
db.collection("Collection").aggregate([
{
$match : {
"someCriteriaFlag" : false
}
},
{
$project : {
"field1" : 1,
"_id" : 0
}
}
]);
在Java
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.match(Criteria.where("someCriteriaFlag").is(false)),
Aggregation.project("field1"));
List<String> fields= mongoTemplate.aggregate(aggregation, "Collection", BasicDBObject.class)
.getMappedResults();
感谢@NeilLunn。
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();
如何 运行 聚合匹配和投影。投影包括一个字段,不包括id。
db.collection("Collection").aggregate([
{
$match : {
"someCriteriaFlag" : false
}
},
{
$project : {
"field1" : 1,
"_id" : 0
}
}
]);
在Java
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.match(Criteria.where("someCriteriaFlag").is(false)),
Aggregation.project("field1"));
List<String> fields= mongoTemplate.aggregate(aggregation, "Collection", BasicDBObject.class)
.getMappedResults();
感谢@NeilLunn。
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();