title: what is the real purpose of $ref (DBRef) in MongoDb
body: <p>I want to use mongo for my app, and while I was thinking about designing issues, I came up with question, so what are the advantages/purposes of DBRef?</p>
  
  <p>for example:</p>
  
  <pre><code>&gt; names = ['apple', 'banana', 'orange', 'peach', 'pineapple']
  [ "apple", "banana", "orange", "peach", "pineapple" ]
  &gt; for (i=0; i&lt;5; i++) {
  ... db.fruits.insert({_id:i, name:names[i]})
  ... }
  &gt; db.fruits.find()
  { "_id" : 0, "name" : "apple" }
  { "_id" : 1, "name" : "banana" }
  { "_id" : 2, "name" : "orange" }
  { "_id" : 3, "name" : "peach" }
  { "_id" : 4, "name" : "pineapple" }
  </code></pre>
  
  <p>and I want to store those fruits in a basket collection:</p>
  
  <pre><code>&gt; db.basket.insert({_id:1, items:[ {$ref:'fruits', $id:1}, {$ref:'fruits', $id:3} ] })
  &gt; db.basket.insert({_id:2, items:[{fruit_id: 1}, {fruit_id: 3}]})
  &gt; db.basket.find()
  { "_id" : 1, "items" : [ DBRef("fruits", 1), DBRef("fruits", 3) ] }
  { "_id" : 2, "items" : [ { "fruit_id" : 1 }, { "fruit_id" : 3 } ] }
  </code></pre>
  
  <p>What are the real difference between those two techniques? For me it looks like using DBRef you just have to insert more data without any advantages.... Please correct me if I'm wrong.</p>