I am trying to load initial data to mongodb using db.collections.insert. I have a case where I'll insert the town collection followed by zipcode collection. The zipcode collection refers to town collection. However when I write my script, I do not know the _id of the town. Would like to know how to build the reference on the fly.
In the e.g. below, I need the id of Mancehster town to be populated in the place of "unkown".
db.town.insert({name:"Manchester",state:{$ref:"state", $id:"CT"},status:"NOT-SUBSCRIBED"});
db.zipcode.insert({_id:"06040", town:{$ref:"town", $id:"unkown"}});
db.zipcode.insert({_id:"06041", town:{$ref:"town", $id:"unkown"}});
db.zipcode.insert({_id:"06042", town:{$ref:"town", $id:"unkown"}});
If there is different way to load my initial data rather than db.collections.insert, I'd like to know that too.