Mongoose in geospatial query box not working correctly

A simple question:
What is the correct way to create a geospatial query from mongoose to nodejs?

Complicated story:
I created a mongoose diagram with a spatial index

var MySchema = newSchema({
// skipped ...
    location : {
        type : [ Number ],
        required : true,
        index : '2d'
    },
// skipped ...
});

Then I inserted into table 3 of the document. I can get these documents with both the mongo client and the mongoose using db.mymodels.find({})andMyModel.find({});

Now I'm trying to make a geospatial query with a bounding box.

db.mymodels.find({location: {$within: {$box: box}}})

returns only one result, as expected, in a field.
Mongoose, on the other hand, returns all three results

query = MyModel.where({location: {$within : {$box : box}}});
query.run(cb)

, find() , find , 'need an area > 0' , , .

? ?

+3
1

, find() where().

, mongoose db, : mongoose.set('debug', true)

0

All Articles