title: GeoJSON and MongoDB: Is it worth it to store points as GeoJSON.Point?
body: <p>With the introduction of <code>2.3 &gt;</code> MongoDB has become even more useful with location data handling and querying. MongoDB stores documents as BSON, so each document with have all the document fields, which obviously potentially leads to larger databases than our conventional RMDBS.</p>
  
  <p>I used to store polylines and polygons as a series of indexed points, with an extra field representing the order of each line (I was doing this to ensure consistency as I use JavaScript, so points weren't always stored in their correct order). It was something like this:</p>
  
  <pre><code>polyline: {
    [
      point: [0,0],
      order: 0
    ],
    [
      point: [0,1],
      order: 1
    ]
  }
  </code></pre>
  
  <p>Whereas now I use:</p>
  
  <pre><code>polyline: {
    type: 'LineString',
    coordinates: [
      [0,0],
      [1,0]
    ]
  }
  </code></pre>
  
  <p>I've seen an improvement in the size of documents, as some polylines can have up to 500 points.</p>
  
  <p>However, I'm wondering what the benefits of storing all my <code>Point</code> data as <code>GeoJSON</code> would be. I am discouraged by the increase in document size, as for example:</p>
  
  <pre><code>loc: [1,0]
  </code></pre>
  
  <p>is way better than </p>
  
  <pre><code>loc: {
    type: 'Point',
    coordinates: [0,1]
  }
  </code></pre>
  
  <p>and would thus be easier to work with.</p>
  
  <p>My question is: </p>
  
  <p><strong>Is it better/recommended to store points as <code>GeoJSON</code> objects as opposed to a 2 point array?</strong></p>
  
  <p>What I have considered is the following:</p>
  
  <ul>
  <li>Size constraints: I could potentially have millions of documents with a location, which might impact the size of the collection, and potentially my pocket.</li>
  <li>Consistency: It would be better do deal with every set of coordinates in the <code>lng, lat</code> format as opposed to sticking to <code>lat, lng</code> for points, and the former for all my other location features.</li>
  <li>Convenience: If I grab a point, and use a <code>$geoWithin</code> or <code>$geoIntersects</code> with it, I wouldn't need to convert it to GeoJSON first before using it as a <code>query</code> parameter.</li>
  </ul>
  
  <p>What I am unsure of is:</p>
  
  <ul>
  <li>Whether support for <code>loc: [x,y]</code> will be dropped in the future on MongoDB</li>
  <li>Any indexing benefits from <code>2dsphere</code> as opposed to <code>2d</code></li>
  <li>Whether any planned <code>GeoJSON</code> additions to MongoDB might result in the need for the consistency mentioned above.</li>
  </ul>
  
  <p>I'd rather move to <code>GeoJSON</code> while my data is still manageable, than switch in future under a lot of strain.</p>
  
  <p><em>May I please kindly ask for a thoroughly (even if slightly) thought out answer. I won't select a correct answer soon, so I can evaluate any responses</em>.</p>
  
  <p><em>I'm also not sure if SO is the right place to pose the question, so if DBA is a more appropriate place I'll move the question there. I chose SO because there's a lot of MongoDB related activity here</em>.</p>