mongodb - spring-data-mongo aggregate filters two fields equal
ringa_lee
ringa_lee 2017-05-02 09:23:59
0
0
1095

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~

ringa_lee
ringa_lee

ringa_lee

reply all(0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template