When using spring-data-mongo for statistics, you need to compare whether two fields are equal, such as l==qzt
just like the query in find
db.dbName.find({$where:"this.l=this.qzt"})
This code can be queried
But when using spring-data-mongo Aggregation, the following error is reported
"errmsg" : "$where is not allowed inside of a $match aggregation expression" , "code" : 16395
This is how I use it:
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);
Is there anything wrong? Or is there any way to compare whether two fields are equal? Thank you~