title: How to set unique id in mongodb with JavaScript
body: <p>I have data like this</p>
  
  <pre><code>Mywants:[
      {"title":"lap","rate":$20}
      {"title":"lap","rate":$20}
      {"title":"lap","rate":$20}
  ]
  </code></pre>
  
  <p>If I save new data into array(mywant) I should save with new unique id so how to save like that using javascript. So it should be look like:</p>
  
  <pre><code>Mywants:[
      {"title":"lap","rate":$20,_id:objectId("512640f3243c837c0e0004401}
      {"title":"lap","rate":$20,_id:objectId("512640f3243c837254000001}
      {"title":"lap","rate":$20,_id:objectId("512640f3243c8372540257001}}
  ]
  </code></pre>
  
  <p>To insert I am using command like</p>
  
  <pre><code>collection.update({"userid":1248787885},{$push:{"Mywant":{"title":"car","rate":$100}}});
  </code></pre>