0

I have this doc:

{
    '_id': 123456,
    'name': 'myName',
    'state':[{'user_id':1,user_state:1},{'user_id':11,user_state:2}]
}

I need to set one more filed ,'is_active':1, in state array object, where "_id" == 123456, and user_id == 11.

As a result it should look like this:

 {
     '_id': 123456,
     'name': 'myName',
     'state': [{'user_id':1,user_state:1},
               {'user_id':11,user_state:2,'is_active':1}]
}

But I am stuck with query:

{_id: new ObjectID(123456)}, {$set:{'state':???}}

Thanks in advance

0

1 Answer 1

1

Try this,

db.colection_name.update({_id: ObjectId("123456"), "state.user_id": 11}, { $set:{ "state.$.is_active" : 1 }})
Sign up to request clarification or add additional context in comments.

3 Comments

will try now. thanks!
worked.thanks. marked your answer.
Happy to help :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.