title: Storing null vs not storing the key at all in MongoDB
body: <p>It seems to me that when you are creating a Mongo document and have a field <code>{key: value}</code> which is sometimes not going to have a value, you have two options:</p>
  
  <ol>
  <li>Write <code>{key: null}</code> i.e. write null value in the field</li>
  <li>Don't store the key in that document at all</li>
  </ol>
  
  <p>Both options are easily queryable, in one you query for <code>{key : null}</code> and the other you query for <code>{key : {$exists : false}}</code>.</p>
  
  <p>I can't really think of any differences between the two options that would have any impact in an application scenario (except that option 2 has slightly less storage).</p>
  
  <p>Can anyone tell me if there are any reasons one would prefer either of the two approaches over the other, and why?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>After asking the question it also occurred to me that indexes may behave differently in the two cases i.e. a sparse index can be created for option 2.</p>