title: In MongoDB, do document _id's need to be unique across a collection or the entire DB?
body: <p>I'm building a database with several collections. I have unique strings that I plan on using for all the documents in the main collection. Documents in other collections will reference documents in the main collection, which means I'll have to save said id's in the other collections. However, if _id's only need to be unique across a collection and not across an entire database, then I would just make the _id's in the other collections also use the aforementioned unique strings.</p>
  
  <p>Also, I assume that in order to set my own _id's, all I have to do is have an <code>"_id":"unique_string"</code> property as part of the document that I insert, correct? I wouldn't need to convert the "unique_string" into another format, right?</p>
  
  <p>Also, hypothetically speaking, would I be able to have a variable save the string "_id" and use that instead? Just to be clear, something as follows: <code>var id = "_id"</code> and then later on in the code (during an insert or a query for example) have <code>id:"unique_string"</code>.</p>
  
  <p>Best, and thanks,<br />Sami</p>