[英]MongoDB $filter doesn't work as expected
这是我对聚合的预测阶段:
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)));
但是它从joins
中返回其exited
状态设置为true
(也为false
)的元素。
你能告诉我我的错误是什么吗?
(我应该提到list
是聚合阶段的ArrayList
)
编辑。 我希望这是一份文件:
{
userName: "test",
//other fields than joins
joins:
[
{
remaining: 4
userID: 1245
exited: false
},
{
remaining: 3
userID: 2312
exited: false
}
]
}
我一直希望exited
是假的。
您必须解析文档值,因为它会被解释为文字字符串值。
更新资料
"cond", "{$eq: [\'$$join.exited\', false]}")
至
"cond", Document.parse("{$eq: [\'$$join.exited\', false]}")
要么
"cond", new Document("$eq", Arrays.<Object>asList("$$join.exited", false))
两种变体都应该起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.