据我了解,你有这样的文档结构:
{
"someProperty" : 1,
"sendingUser" : {
userID : 34343,
name : "Joe Bloggs"
},
"recivingUser" : {
userID : 34345,
name : "Joe Bloggs"
}
}
因此,如果您需要发送用户ID为34345的发送用户,则只需执行以下操作(我认为是这样,因为实际上我正在为mongo使用C#驱动程序):
DBCollection coll = db.getCollection("privateMessages")
query = new BasicDBObject();
query.put("sendingUser.userID", new BasicDBObject("$eq", 34345));
cur = coll.find(query); // all documents with sendingUser.userID = 34345 will be //returned by cursor
另请查看Java驱动程序教程