0

How can we update a value for 'Enabled' field in Configuration at index 1 in Configurations Array in mongo database ?

Below is my Json data.

{
    "Configurations" : [ 
                           {
                               "Configuration" : {
                                   "Host" : "",
                                   "Port" : "1521",
                                   "Enabled" : "true"                 
                               }
                            }, 
                            {
                               "Configuration" : {
                               "Host" : "",
                               "Port" : "",
                               "Enabled" : "true"
                               }                                  
                            }
                        ],
    "Description" : "Check Database Server"                   
}

Is there any way to update value for Enabled field in Configuration ?? How can we update a value for 'Enabled' field in Configuration at index 1 in Configurations Array in Mongodba ?

I want to update Enabled field value of 2nd configuration in Configurations Array.

3

2 Answers 2

2

What about something like this

db.collection.update({}, 
    { "$set": { "Configurations.1.Configuration.Enabled": false }}
)
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I want something like this but what value we should pass for ... in the below code. db.collection.update( ''....'', { "$set": { "Configurations.1.Configuration.Enabled": false }} )
0

Try this:

db.collection.update({
"Configurations": {
    "$elemMatch": {
        "Configuration.Port": "1521"
    }
}
}, {
"$set": {
    "Configurations.$.Configuration.Enabled": "false"
}
})

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.