Given a collection of documents like this, I want to delete 'bored' state from member 'b'.
Without knowing the array index of member b.
doc = {'_id': ObjectID(),
'name': 'the_name',
'location': 'the_location',
'members': [{'membername': 'a',
'membernum': '13',
'states': ['hungry', 'tired', 'happy']},
{'membername': 'b',
'membernum': '8',
'states': ['bored', 'glad']}]
}
If I knew the array index, I would use the code below, but I don't know how to change that to a situation where I only know the member name.
doc.update({name:'the_name'},
{"$unset": {"members.1.states.0": 1});
doc.update({name:'the_name'},
{"$pull": {"members.1.states": null}});
Is it possible to delete a specific element from an array in an array of subdocuments?
thanks,
--Tim