Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating Nested Embedded Documents in mongodb
    primarykey
    data
    text
    <p>I am new to mongodb. Plz help me with this.</p> <p>I need a document like this</p> <pre><code> employee{ _id:111, name:xxx, dependents : [ { name:a, age:51, dep_children:[{name:aa}{name:bb}{name:c}] } { name:b, age:52, dep_children:[{name:aa}{name:bb}{name:c}] } { name:c, age:51, dep_children:[{name:aa}{name:bb}{name:cc}] } ] } </code></pre> <p>I am using the below script to migrate data for SQL and update it into mongoDB</p> <p>My code looks something like this:</p> <pre><code> while(personcount&gt;=0) { BasicDBObject doc = new BasicDBObject("_id",ind1.get(count)). append("name",ind2.get(count)); coll.insert(doc); while(dependentcount&gt;0) { BasicDBObject querymongo = new BasicDBObject(); querymongo.put( "name",ind.get(count)); BasicDBObject tenant = new BasicDBObject(); tenant.put("name",indsa.get(innercount) ); tenant.put("age", indsa2.get(innercount)); BasicDBObject update = new BasicDBObject(); update.put("$push", new BasicDBObject("dependents",tenant)); coll.update(querymongo, update,true,true); while(kidcount&gt;0) { BasicDBObject querymongofact = new BasicDBObject(); querymongokid.put( "dependent.name",indsa.get(innercount)); BasicDBObject tenantkid = new BasicDBObject(); tenantkid .put("name",indfact.get(innercountfact) ); BasicDBObject updatekid = new BasicDBObject(); updatekid .put("$push", new BasicDBObject("dependent.dep_children",tenantkid)); coll.update(querymongokid, updatekid ,true,true); } } } </code></pre> <p>when we print querymongokid and updatekid, the data inside it are expected values itself. This code is not throwing any error. But in data base the only dep_children data is not getting updated . I am not getting wt went wrong. please help me </p> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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