Mongo汇总查询的Java代码包含$ push
下面是用于Mongo查询的管道片段。以及我要编写的相应的Java代码。 我会遇到“未识别的表达式”错误。有人可以让我知道Java代码出了什么问题吗? 其他管道似乎还不错。问题是$ push。
我使用的是Mongo Driver 3.8.2,
"$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"
}
}
下面的Mongo 5版本是上述摘要异常的Java代码
Bson group = new Document("$group", new Document("_id", idDoc).append("data", new Document("$push", pushDoc)).append("dataKey", new Document("$first", "$_id."+orderBy)));
,如下所示。
"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)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论