Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One thing is suggested when defining your doc structure: Avoid using <code>_id</code> in your own schema, as this name is internal of mongodb to represent the ObjectId. If it is strict that you do so, use <code>id</code> instead. Please see <a href="http://docs.mongodb.org/manual/reference/object-id/" rel="nofollow">http://docs.mongodb.org/manual/reference/object-id/</a>. </p> <p>So your document can now be like:</p> <pre><code>{ "id" : "f9d01fd1ef22684353149851", "name" : "Ueberschrift", "items" : [ { "id" : "be695ec7ffe71152088c57e1", "name" : "iop", "checked" : false, "subitems" : [ ] }, { "id" : "fe665ec7ffe78852088c22g8", "name" : "asd", "checked" : false, "subitems" : [ ] } ] } </code></pre> <p>the update query:</p> <pre><code>Listitems.update({ id:"f9d01fd1ef22684353149851", "items.id" : "be695ec7ffe71152088c57e1"}, {$push: {"items.$.subitems" :{ id : 1, name : "MySubitemName" }}}); </code></pre> <p>I've tested using mongodb console, and I'm assuming the object supplied in the update query matches that of the console.</p> <p>Please tell us if that worked.</p> <p><strong>EDIT to improve comment</strong>: Since you are meaning the actual object id (<code>_id</code>) when querying, please have a look a the code below, adapted as a possible fix for the object referencing:</p> <pre><code>uid =&gt; ObjectId("f9d01fd1ef22684353149851") and id =&gt; ObjectId("be695ec7ffe71152088c57e1") Listitems.update({_id:uid, "items._id" : id}, {$push: {"items.$.subitems" :{ id : 1, name : "MySubitemName" }}}); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload