当前位置: 代码迷 >> 综合 >> Mongoose - 嵌套查询
  详细解决方案

Mongoose - 嵌套查询

热度:14   发布时间:2024-01-15 11:36:09.0

示例数据:

{"_id" : ObjectId("5ca560896208983d3c55b87e"),"createdBy" : {"kind" : "admin","item" : ObjectId("5c9d84c98a007636043f1fe6")}
}

完全匹配嵌套数据进行查询:

db.getCollection('xxxx').find({ "createdBy": { "kind": "admin", "item": ObjectId("5c9d84c98a007636043f1fe6")}})

部分匹配嵌套数据进行查询:

db.getCollection('trainingEntries').find({"createdBy.kind": "admin"})