【发布时间】:2014-01-14 20:52:14
【问题描述】:
我在 mongoose 版本 3.8.3 中使用 mongoDB $nearSphere 方法来查找附近的位置。
mongoose.models['Event']
.find({ loc :
{
$nearSphere :
{
$geometry : loc,
$maxDistance : 100000
}
}
})
.limit(100)
.exec(function (err, events)
{
console.log(err)
...
}
Events Scheme 中的 loc 字段有一个 '2dsphere' 索引:
var EventSchema = new Schema
({
...
loc:
{
type: { type: String },
coordinates: { type: [Number], index: '2dsphere' }
},
...
});
变量 loc 的类型为“Point”。一个例子是:
{ coordinates: [ 12.93598683338508, 48.43299197266921 ], type: 'Point' }
执行上面的搜索语句后总是报错:
2013-12-27T08:46:57.997102+00:00 app[web.1]: { message: 'Cast to number failed for value "Point" at path "__QueryCasting__"',
2013-12-27T08:46:57.997105+00:00 app[web.1]: name: 'CastError',
2013-12-27T08:46:57.997107+00:00 app[web.1]: type: 'number',
2013-12-27T08:46:57.997108+00:00 app[web.1]: value: 'Point',
2013-12-27T08:46:57.997110+00:00 app[web.1]: path: '__QueryCasting__' }
谁能弄清楚为什么会出现这个错误以及如何解决它?
【问题讨论】:
标签: node.js mongodb mongoose geospatial geo