您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

MongoDB嵌套文档搜索

MongoDB嵌套文档搜索

据我了解,你有这样的文档结构:

{
   "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驱动程序教程

mongodb 2022/1/1 18:31:12 有502人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶