Java MongoDB$筛选器无法按预期工作
这是我的聚合投影阶段:Java MongoDB$筛选器无法按预期工作,java,mongodb,aggregation-framework,mongo-java,mongo-java-driver,Java,Mongodb,Aggregation Framework,Mongo Java,Mongo Java Driver,这是我的聚合投影阶段: Document filter = new Document( "$filter", new Document( "input", "$joins").append("as", "join").append( "cond", "{$eq: [\'$$join.exited\', false]}")); li
Document filter = new Document(
"$filter", new Document(
"input", "$joins").append("as", "join").append(
"cond", "{$eq: [\'$$join.exited\', false]}"));
list.add(project(new Document("_id", 0).append("joins", filter).append("userName", 1)
.append("chatID", 1).append("warned", 1)));
但它从连接返回元素,这些元素的exit设置为true,也设置为false。
你能告诉我什么是我的错吗?
我应该提到,list是聚合阶段的ArrayList
编辑。我希望这是一份文件:
{
userName: "test",
//other fields than joins
joins:
[
{
remaining: 4
userID: 1245
exited: false
},
{
remaining: 3
userID: 2312
exited: false
}
]
}
我希望exited始终为false。您必须解析文档值,因为它被解释为文本字符串值 更新
"cond", "{$eq: [\'$$join.exited\', false]}")
到
或
这两种变体都应该有效。您可以添加您希望查询返回的示例文档吗?非常有效。谢谢
"cond", Document.parse("{$eq: [\'$$join.exited\', false]}")
"cond", new Document("$eq", Arrays.<Object>asList("$$join.exited", false))