MongoDB "find" 包含多个查询文档的查询

MongoDB "find" query with multiple query documents

我正在使用 MongoDB 3.2 和 Java。我阅读了文档,它说要使用 org.bson.BsonDocument,因为 BSONObjectDocument 等其他选项已弃用。现在,我的查询类似于:

db.schools.find({ zipcode: "63109" },
    { students: { $elemMatch: { school: 102 } } } )

我想知道:如何在 Java 中编写此查询?

注意: 这里我们在 find 函数中有两个文档,而它只接受单个 Bson Document 或多个 Bson Element(s ).

如有任何帮助,我们将不胜感激。

条件尽量用一个文档,比如db.schools.find({ zipcode: "000000", students: { $elemMatch: { school: 102 }});

编辑:

所以,您正在使用投影。在java mongodb driver 3.3 中有: public DBCursor find(DBObject query, DBObject projection)。我认为您应该更新 java mongodb 驱动程序。