【问题标题】:Get nested document using mongoose使用猫鼬获取嵌套文档
【发布时间】:2018-10-13 16:55:06
【问题描述】:

如何使用 mongo db _id 查找嵌套文档。

{  
    "_id": "5aead7541b5cd15fb70b4c61",
    "name": "myconversation",
    "nodes": [{
            "_id": "5aead7541b5cd15fb70b4c62",
            "plugin_id": "text_card",
            "title": "First Card",
            "text": "my text"
        }]
}

【问题讨论】:

  • 嗨 Chaitanya Thakre,欢迎来到 Stack Overflow 我认为您的问题的答案是使用点表示法,但很难确定,因为您没有包含你的问题有很多细节。您能否在edit 中包含您希望获得的查询结果,以及到目前为止您尝试过哪些或哪些查询以及为什么它们不起作用?
  • 你的意思是在数组中找到_id?还是文档根目录中的_id?需要更多细节
  • 需要更多解释

标签: mongodb mongoose


【解决方案1】:

假设你想用_id查询数组节点内部:

db.collection.find({节点:{$elemMatch:{_id:“5aead7541b5cd15fb70b4c62”}}})

【讨论】:

    【解决方案2】:

    你可以像下面这样的数据。

    db.collection.find({ 'nodes._id': "5aead7541b5cd15fb70b4c62" });

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-08
      • 1970-01-01
      • 2020-08-18
      • 1970-01-01
      • 2019-12-16
      • 1970-01-01
      • 2014-05-30
      相关资源
      最近更新 更多