mongoDB正确的find()命令

时间:2018-06-28 09:57:59

标签: bash mongodb search find

我有一个对象看起来像的集合:

{
  "_id":ObjectId(""),
  "payload":{
  "roles":[
     {
        "contract_part":"1111",
        "role_key":"",
        "party_key":"29-29",
        "address_key":null,
        "changed_at":"2017-07-18T18:30:00",
        "changed_nr":NumberLong(1),
        "type":NumberLong(33),
        "contract_key":"999",
        "business_to":"2999-01-01T00:00:00",
        "business_from":"2017-07-18T18:30:00"
     }
  ]
},
   "id":NumberLong("10345"),
   "event":"role.created",
   "aggregate":"role",
   "timestamp":"2017-07-18T21:30:00.000+03:00"
}

我努力创建一个db.collection.find(),使我能够找到具有特定"role_key"的对象。

1 个答案:

答案 0 :(得分:1)

尝试使用此

db.collection.find({"payload.roles": {$elemMatch: {role_key:" "}}})