user4523328
user4523328

Reputation:

Updating array inside two object in mongod

I have a collection of the structure as follows:

collection name : "positions"

Structure

{
    "_id" : "vtQ3tFXg8THF3TNBc",
    "candidatesActions" : {
        "sourced" : [ ],
    },

    "appFormObject" : {
        "name" : "✶ mandatory",
        "questions" : [
            {
                "qusId" : "qs-585494",
                "type" : "simple",
                "qus" : "Which was your previous company"
            },
            {
                "qusId" : "qs-867766",
                "type" : "yesNo",
                "qus" : "Are you willing to relocate?",
                "disqualify" : "true"
            }
        ]
    }
}

I want to update "qus" field of the above collection whose _id is "vtQ3tFXg8THF3TNBc" and "qusId" is "qs-585494".

Upvotes: 1

Views: 44

Answers (2)

Dineshaws
Dineshaws

Reputation: 2083

Use following query

db.positions.findAndModify({
    query: { _id: "vtQ3tFXg8THF3TNBc", "appFormObject.questions.qusId":"qs-585494"} ,
    update: { $set: { 'appFormObject.questions.$.qus': 'Brilliant Green' } },
});

Thanks

Upvotes: 0

Shreyance Jain
Shreyance Jain

Reputation: 944

Try following....

db.positions.update(
  {_id: "vtQ3tFXg8THF3TNBc", "appFormObject.questions.qusId":"qs-585494"},
  {$set:{"appFormObject.questions.$.qus": "this is updated value"}}
)

Upvotes: 1

Related Questions