这是我对聚合的预测阶段:
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))
两种变体都应该起作用。