Closed cultofmetatron closed 10 years ago
:+1:
:+1:
Thanks for pointing this out, I'm on it.
@cultofmetatron @gdi2290 @Mayho this isn't actually an issue with mongoose. If you take a look at the docs for MongoDB's $geoWithin
operator, you'll see that you need another set of square braces. This is because $geoWithin
provides an interface for dealing with polygons with multiple rings. For example, the following code:
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var Car = mongoose.model("Car", {
loc: { lat: Number, lng: Number }
});
mongoose.connect("mongodb://localhost/2092");
var db = mongoose.connection;
db.on("open", function() {
Car.
find().
where('loc').
within({
type: 'Polygon',
coordinates: [
[
[-122.523566, 37.808835],
[-122.390786, 37.814938],
[-122.368384, 37.763184],
[-122.528716, 37.744454],
[-122.523566, 37.808835]
]
]
}).
exec(function(error, cars) {
console.log(error);
});
});
works as expected. I agree this is a bit of a gotcha, but I think this qualifies as "works as designed", although I'd be happy to hear arguments to the contrary.
I'm creating some methods to simplify certain geoqueries in our new tracking application and I'm having no luck getting geojson to work as query parameters.
for instance, given a method
I'm finding in my test that using a geoJson object in my within clause causes an error in the code but using the mongoose specific "polygon": [[] [] []] style works just fine.
is this a known issue? I'm using mongo 2.6.1 with mongoose 3.8.9