Simple question:
what is the proper way of making a geo-spatial query with mongoose on nodejs?
Complex story:
I created a Schema with mongoose with a spatial index
var MySchema = newSchema({
// skipped ...
location : {
type : [ Number ],
required : true,
index : 2d
},
// skipped ...
});
Then I inserted into the table 3 documents.
I can retrieve these documents with both mongo client and mongoose
using db.mymodels.find({})
and MyModel.find({});
Now I try to make a geo-spatial query with a bounding box.
mongo client works ok
db.mymodels.find({location: {$within: {$box: box}}})
returns only one result as expected, within the box.
Mongoose on the other hand, returns back all three results
query = MyModel.where({location: {$within : {$box : box}}});
query.run(cb)
This question says you should use find() instead of where,
but when I tried replacing find with where, I got an error need an area > 0
I checked, my bounding box is formatted correctly, lower-left then upper-right.
What to do? What is the proper way to make a geo-spatial query with a bounding box using mongoose?