Below is a pipeline snippet for mongo query. And the corresponding Java code that I'm trying to write. I'm getting the error 'Unrecognized expression '$push''. Can someone please let me know what is wrong with the Java code? Other pipelines seem to be fine. Issue is with $push.
I'm using mongo driver 3.8.2 with latest Mongo 5 version
"$group": {
"_id": {
"a": "$_id.a",
"b": "$_id.b"
},
"data": {
"$push": {
"c": "$_id.c",
"customerCount": {
"$sum": "$customerCount"
},
"itemQuantity": {
"$sum": "$itemQuantity"
},
"amount": {
"$sum": "$amount"
}
}
},
dataKey: {
$first: "$_id.c"
}
}
Below is the Java code for above snippet
Bson group = new Document("$group", new Document("_id", idDoc).append("data", new Document("$push", pushDoc)).append("dataKey", new Document("$first", "$_id."+orderBy)));
Exception is as shown below.
"com.mongodb.MongoCommandException: Command failed with error 168 (InvalidPipelineOperator): 'Unrecognized expression '$push'' on server localhost:27017. The full response is { \"ok\" : 0.0, \"errmsg\" : \"Unrecognized expression '$push'\", \"code\" : 168, \"codeName\" : \"InvalidPipelineOperator\" }\r\n\tat com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:179)