learning developer
learning developer

Reputation: 449

Mongo db - Querying documents using nested field (nested array and objects)

{
  "_id":"12345",
  "model":{
     "T":0,
     "serviceTask":[
        {
          "_id":"6789",
           "obj":{
             "params" :{
                "action": "getEmployeeData",
                "employeeId":"123"
             },
             "url":"www.test.com",
             "var":"test",
           },
           "opp":100
        }
     ]
  }
}

I have similar structured documents in my collection. How do I query the documents that match action value to "getEmployeeData". I tried dot notation with $elemMatchbut couldn't get the results.

Upvotes: 1

Views: 49

Answers (1)

mickl
mickl

Reputation: 49945

Dot notation works fine here, it will return the document if serviceTask contains at least one action set to getEmployeeData

db.collection.find({
    "model.serviceTask.obj.params.action": "getEmployeeData"
})

Upvotes: 2

Related Questions