这是我对聚合的预测阶段:

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))


两种变体都应该起作用。

09-27 22:18