mongodb 过滤嵌套文档数组

时间:2021-02-21 18:56:48

标签: mongodb-query

我想找到一个并通过 moduleIdname 过滤配置文件

 {
    "moduleId": 1,
    "access": {
      "del": ..,
      "editWrite": ...,
      "read": ....
    }
  }

文档看起来像这样:

    "profileAccess": [
      {
        "moduleId": 1,
        "access": {
          "del": true,
          "editWrite": true,
          "read": true
        }
      },
      {
        "moduleId": 2,
        "access": {
          "del": true,
          "editWrite": true,
          "read": true
        }
      }
      
    ],
    "name": "admin"
   },

1 个答案:

答案 0 :(得分:0)

找到答案了,我好像忘记回复了

Profile.findOne({name:"admin"},{profileAccess: { $elemMatch: { moduleId: 1} }});