I have objects like the following:
{
"_id" : ObjectId("4f7f0d64e4b0db1e18790f10"),
"location" : [
0.674081,
23.473
],
"name" : "Item Name"
}
If I try and create a 2D index on the location field, I get an error:
> db.Place.ensureIndex({location:"2d"});
point not in interval of [ -180, 180 )
I’ve tried finding documents that are out of bounds but this returns no results:
> db.Place.find({"location.0":{"$lte":-180, "$gte":180}});
> db.Place.find({"location.1":{"$lte":-180, "$gte":180}});
I’ve also tried the following queries to make sure:
> db.Place.find({"location":{"$size":0}}).count();
0
> db.Place.find({"location":{"$size":1}}).count();
0
> db.Place.find({"location":{"$size":2}}).count();
363485
> db.Place.count();
363485
What other approaches can I use to find the bad document(s)?
For information I’m using MongoDB version 2.0.2 on 32 bit Linux (yes, I know that’s not good enough for prod). The documents were imported by a Java document where the location objects are only ever represented as double primitives.
Your queries aren’t quite right. You need:
And