I have a multi level schema and I\'m trying to add an element to a list in a deep level using the $ operator.
My schema looks like this and I\'m trying to add an object
The $ operator is for use in the update operator object (2nd argument to update
), not the query selector (1st argument). In the query selector, you should be able to use aList.bList.cList._id
, and this would let aList.$.bList.$.cList
correspond to the first matching element of the embedded cList
in the update operator.
Edit:
Nested positional ($
) operator matching is not supported currently. This ticket shows demand for exactly this feature from a long time ago (2010!), but apparently lower-level code within mongoDB did not make this possible. It seems 10gen is hopeful to get this feature in the 2.6 release.
It looks like you will have to separately query and update to achieve this with your current schema, or perhaps change your schema to be more flat.