mongodb - How does mongoose query data based on the id of a subdocument?
为情所困
为情所困 2017-05-17 10:03:14
0
2
693
{
    "_id": "590ad2c78eb79d16bde4a15d",
    "user": "yejia@qq.com",
    "password": "111111",
    "__v": 0,
    "lists": [
      {
        "_id": "590ad2d78eb79d16bde4a15e",
        "update_at": "2017-05-04T07:05:52.174Z",
        "create_at": "2017-05-04T07:05:52.174Z",
        "title": "测试1",
        "isChecked": [
          false
        ],
        "details": [
          "未完"
        ]
      },
      {
        "_id": "590ad3398eb79d16bde4a15f",
        "update_at": "2017-05-04T07:07:28.784Z",
        "create_at": "2017-05-04T07:07:28.784Z",
        "title": "测试2",
        "isChecked": [
          false,
          false
        ],
        "details": [
          "1232",
          "333"
        ]
      }
    ]
  }

Like this example, if I want to find a subdocument based on its id: "_id": "590ad2d78eb79d16bde4a15e", what should I do? To explain, I know how to query directly by id. What I don’t understand is how to query subdocuments using the id of the subdocument.

为情所困
为情所困

reply all(2)
仅有的幸福

You can view the API documentation of mongoose, the chapter about sub_doc operation, http://mongoosejs.com/docs/subdocs.html

曾经蜡笔没有小新

yourCollectionName.lists.id(your_id)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template