如何过滤mongodb java文档的嵌套数组
如何使用Java(Bson Documents)过滤同样包含对象的对象数组 例如,我有一个用户,其数组=跟随用户。现在我想从该列表中筛选特定用户,我该怎么做? 我尝试过这样的smth,但我不知道,因为这越来越复杂:如何过滤mongodb java文档的嵌套数组,java,mongodb,filter,nested,bson,Java,Mongodb,Filter,Nested,Bson,如何使用Java(Bson Documents)过滤同样包含对象的对象数组 例如,我有一个用户,其数组=跟随用户。现在我想从该列表中筛选特定用户,我该怎么做? 我尝试过这样的smth,但我不知道,因为这越来越复杂: Document filter = new Document("follows", new Document("$elemMatch", eq("uID", uID))); 您是否尝试过聚合管道,可以在其中展开follows数组,然后设置匹配条件?我不知道如何使用java实现这一
Document filter = new Document("follows", new Document("$elemMatch", eq("uID", uID)));
您是否尝试过聚合管道,可以在其中展开follows数组,然后设置匹配条件?我不知道如何使用java实现这一点,但使用javascript您可以这样做
db.collection.find({follows:{$elemMatch:{uID:{int3}}},{follows:{$elemMatch:{uID:{int3}}}})
。。。您可以尝试在java中解决此问题的语法