mongodb - spring-data-mongo aggregate 筛选两个字段相等

 winnie198808616 发布于 2022-10-26 18:50

在使用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 results = events2Data.agreagate(agg);

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

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有