[英]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? 在nodejs上使用mongoose进行地理空间查询的正确方法是什么?
Complex story: 复杂的故事:
I created a Schema with mongoose with a spatial index 我用带有空间索引的mongoose创建了一个Schema
var MySchema = newSchema({
// skipped ...
location : {
type : [ Number ],
required : true,
index : '2d'
},
// skipped ...
});
Then I inserted into the table 3 documents. 然后我插入表3中的文件。 I can retrieve these documents with both mongo client and mongoose using db.mymodels.find({})
and MyModel.find({});
我可以使用db.mymodels.find({})
和MyModel.find({});
同时使用mongo客户端和db.mymodels.find({})
检索这些文档MyModel.find({});
Now I try to make a geo-spatial query with a bounding box. 现在我尝试使用边界框进行地理空间查询。
mongo client works ok mongo客户端工作正常
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 另一方面,Mongoose返回所有三个结果
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. 这个问题说你应该使用find()而不是where,但当我尝试用where替换find时,我得到一个错误'need an area > 0'
我检查过,我的边界框格式正确,左下角然后右上角。
What to do? 该怎么办? What is the proper way to make a geo-spatial query with a bounding box using mongoose? 使用mongoose使用边界框进行地理空间查询的正确方法是什么?
It doesn't matter if you use find()
or where()
. 使用find()
或where()
无关紧要。
Would you mind posting what mongoose is sending to the db by enabling logging and checking your console: mongoose.set('debug', true)
您是否可以通过启用日志记录并检查控制台来发布mongoose发送到数据库的内容: mongoose.set('debug', true)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.