Note that there are some explanatory texts on larger screens.

plurals
  1. POmongodb's ensureIndex doesn't work accurately
    primarykey
    data
    text
    <p>mongodb version: osx-x86_64-2.4.5</p> <p>I have a collection of users with geolocation data in the following form:</p> <pre><code>[ { "_id" : "24128f74-3e47-4f02-8188-37779f3eca3c", "geolocation" : { "lat" : 55.5884705, "lng" : 13.0111425 } }, { "_id" : "65db4271-8eff-4619-95fb-08135cbccb8f", "geolocation" : { "lat" : 55.58934530000001, "lng" : 13.0066488 }, "email" : "stephan3@stephan3.com" }, { "_id" : "74d17da5-af4c-4386-9efa-9817f11b64f9", "geolocation" : { "lat" : 55.58934530000001, "lng" : 13.0066488 } }, { "_id" : "d0378d09-1f69-4e01-8602-b4805466a029", "geolocation" : { "lat" : 55.590957, "lng" : 13.001412 } } ] </code></pre> <p>As I don't want to migrate any production data, I created an index to be able to use geospatial queries such as <em>$geoWithin</em> as documented here <a href="http://docs.mongodb.org/manual/tutorial/build-a-2dsphere-index/" rel="nofollow">http://docs.mongodb.org/manual/tutorial/build-a-2dsphere-index/</a>:</p> <pre><code>db.user.ensureIndex({ geolocation : '2d'}) </code></pre> <p>If I query the <em>user</em> collection like in the following way, I get an empty array back</p> <pre><code>db.user.find({ geolocation: { $geoWithin : { $center : [ [ 13.0111425,55.5884705 ], 1 ] } }}); </code></pre> <p>Note that this is the exact location as user 24128f74-3e47-4f02-8188-37779f3eca3c, so at least she should be returned.</p> <p>When I convert the users' geolocation property into the [ long, lat ] format, so a user entry looks like the following, and then apply the same query again, I get all users, also the ones that are further away.</p> <pre><code>[ { "_id" : "24128f74-3e47-4f02-8188-37779f3eca3c", "geolocation" : [ 13.0111425, 55.5884705 ] }, ... ] </code></pre> <p>Do you have an idea what might be going wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload