How to update a collection in mongodb
<p>I had a json which is inserted in my mongo collection.Now I want to update the same json that is inserted in the collection,in such a way that I need to add new data element to that collection using the id which will be generated earlier.
eg:</p>
<pre><code>{
 &quot;name&quot;:&quot;sam&quot;,
 &quot;age&quot;:20,
  &quot;_id&quot;:&quot;&quot;5sq8uye1236g'
 }
</code></pre>
<p>If above is the json what is inserted in one collection where we have <code>_id</code> generated for it in collection.
Now I had variable called token .</p>
<p>var token=12345</p>
<p>Now I want to update the above collection such that this token gets added to it based on the <code>_id</code> of that.
Required format in collection:</p>
<pre><code>{
&quot;name&quot;:&quot;sam&quot;,
&quot;age&quot;:20,
 &quot;token&quot;:12345,
&quot;_id&quot;:&quot;&quot;5sq8uye1236g'
 } 
</code></pre>
<p>How can I do that?</p>