title: Weird behavior with mongodb fields start with $
body: <p>On this post <a href="https://stackoverflow.com/questions/8983482/mongodb-finding-nested-elements">MongoDB finding nested elements</a>, author claims that the mongodb document structure is </p>
  
  <pre><code>      car : { "$ref" : "cars" , "$id" : { "$oid" : "4e8478ace4b0dea06288ad63"}}
  </code></pre>
  
  <p>When i tried to reproduce the problem, i encountered some weird behaviors with mongodb insertion</p>
  
  <p>When  run the insertion on above sample data, i got following error</p>
  
  <pre><code>&gt; db.sample.insert({car:{ "$ref" : "cars" , "$id" : { "$oid" : "4e8478ace4b0dea06288ad63"}}})
  Tue Jan 24 14:09:07 uncaught exception: field names cannot start with $ [$oid]
  </code></pre>
  
  <p>it says that field names cannot  start with <code>$</code>.</p>
  
  <p>If thats the case, it should not work if i remove <code>$</code> from oid and left the remaining <code>$ref</code> &amp; <code>$id</code> untouched </p>
  
  <pre><code>    &gt; db.sample.insert({car:{ "$ref" : "cars" , "$id" : { "oid" : "4e8478ace4b0dea06288ad63"}}})
      &gt; db.sample.find()
  { "_id" : ObjectId("4f1e6fbc403aae757ec6dea5"), "car" : { "$ref" : "cars", "$id" : { "oid" : "4e8478ace4b0dea06288ad63" } } }
  </code></pre>
  
  <p>surprisingly it worked. Now it accepts the fields start with $</p>
  
  <p>Also when i tried this query</p>
  
  <pre><code>&gt; db.sample.insert({ "$ref" : "cars" })
  document to insert can't have $ fields
  </code></pre>
  
  <p>i got the error back.</p>
  
  <p>I don't understand what causes this? anybody have a clear idea?</p>