为了账号安全,请及时绑定邮箱和手机立即绑定

mong模板聚合匹配和投影一个字段,没有id

mong模板聚合匹配和投影一个字段,没有id

慕桂英4014372 2022-09-21 17:29:40
如何运行具有匹配和投影的聚合。投影包括一个字段并排除 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();


查看完整回答
反对 回复 2022-09-21
  • 1 回答
  • 0 关注
  • 182 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号