title: Mongodb multikey index
body: <p>I want to make sure I'm creating the right index for my data structure (documents in mongodb).</p>
  
  <p>My document contains <strong>list of items</strong>, and each item contain <strong>list of locations</strong>.
  I'm searching for items using it's location, and I want to <strong>create the right index</strong> for this kind of search.</p>
  
  <pre><code>   { # &lt;- document
        "items": [
             {   # &lt;- first item
                 "name": "Item Name",
                 "locations": [
                      { # &lt;- first location
                         "sw":{"lat":0, "lng":0},
                         "ne":{"lat":0, "lng":0},
                      },
                      { # &lt;- second location
                         "sw":{"lat":0, "lng":0},
                         "ne":{"lat":0, "lng":0},
                      },
                      { # &lt;- more locations...
                        ...
                      },
                 ]
             },
             {   # &lt;- second item
                ...
             }
        ]
     }
  </code></pre>
  
  <p>I'm searching for items using the <strong>lat</strong> and <strong>lng</strong> values, and I've used "ensureIndex" with the following key to create the index:</p>
  
  <pre><code>db.&lt;collection&gt;.ensureIndex({"items.locations.sw.lat":1});
  db.&lt;collection&gt;.ensureIndex({"items.locations.sw.lng":1});
  db.&lt;collection&gt;.ensureIndex({"items.locations.ne.lat":1});
  db.&lt;collection&gt;.ensureIndex({"items.locations.ne.lng":1});
  </code></pre>
  
  <p>Is it the right way?</p>
  
  <p>Thanks</p>