English 中文(简体)
盒式地理空间电离层中的阳光并不正确。
原标题:mongoose within box geo-spatial query does not work correctly

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?

最佳回答

如果您使用<代码>find(或 where(),则无事项。

Would you mind posting what mongoose is sending to the db by enabling logging and checking your console: mongoose.set( debug , true)

问题回答

暂无回答




相关问题
Google maps KM bounds box reapplying itself on map zoom

I have a map in which I apply a custom overlay using KMbox overlay to signify where I think the users general point of interest lies. What I want is to display this map to the user and allow them to ...

Do I need a spatial index in my database?

I am designing an application that needs to save geometric shapes in a database. I haven t choosen the database management system yet. In my application, all database queries will have an bounding ...

Calculate the bounding box of a GDI+ drawing

I am drawing an image from MetaFile (emf) and then apply some rotation transformations to it all within the OnPaint of a UserControl. After applying those transformation how can I calculate the normal ...

热门标签