"Find() inside Insert" in MongoDB?
<p>Folks,
I have a collection called 'Animals', example documents -</p>

<pre><code>{
    "_id" : ObjectId("57321290c46ff86ce9e00b35"),
    "parent_id" : null,
    "author" : "xxx@hotmail.com",
    "name" : "Mammal",
    "status" : "active",
    "sub_species" : [ 
        "Dog", 
        "Cat", 
        "Cow"
    ]
}

{
    "_id" : ObjectId("57321c10c46ff86ce9e00b36"),
    "author" : "xxx@hotmail.com",
    "name" : "Dog",
    "status" : "active",
    "parent_id" : "57321290c46ff86ce9e00b35"
}
</code></pre>

<p>My question is this - How do I write an Insert-statement in mongo shell to programmatically generate the 'parent-id' (if it already exists) ? I want to be able to write something like this -</p>

<pre><code>db.animals.insert( {
    "author" : "xxx@hotmail.com",
    "name" : "Dog",
    "status" : "active",
    "parent_id" : {db.animals.find( { name: { $eq: 'Mammal' } } )}
} )
</code></pre>

<p>Thanks in advance</p>