登录  /  注册
mongodb - spring-data-mongo aggregate 筛选两个字段相等
ringa_lee
ringa_lee 2017-05-02 09:23:59
[MongoDB讨论组]

在使用spring-data-mongo做统计时,需要比较两个字段是否相等,比如 l==qzt
就像find中查询

db.dbName.find({$where:"this.l=this.qzt"})

这段代码是能查询出来的
但是在使用spring-data-mongo Aggregation的时候 就报以下错误

"errmsg" : "$where is not allowed inside of a $match aggregation expression" , "code" : 16395

我是这样用的:

Criteria c = Criteria.where("$where").is("this.qzt==this.l");
Aggregation agg =Aggregation.newAggregation(
    Aggregation.match(c),
    Aggregation.group("qzc").count().as("z"),
    Aggregation.project("z").and("qzc").previousOperation(),
    Aggregation.sort(Sort.Direction.DESC, "z")
);
List<Events2> results = events2Data.agreagate(agg);

请问各位是哪里有错吗,或者,有什么方法能比较一下两个字段是否相等吗?拜谢~

ringa_lee
ringa_lee

ringa_lee

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号