Mongoose $ near查询返回parsing错误
这是一个对象的例子:
{ "_id" : "581994", "type" : "Feature", "geometry" : { "type" : "Point", "coordinates" : [ -149.0133, 64.7439 ] } }
这是我执行的查询:
Earthquake .find({ geometry: { $near: { $geometry: { type: 'Point', coordinates: [lon, lat] } } } }) .exec(function(err, results) { if (err) { console.log(err); } return reply(results); })
这是我创build的模型模式:
var mongoose = require('mongoose'); mongoose.set('debug', true); var Schema = mongoose.Schema; var earthquakeSchema = new Schema({ geometry: { type: String, coordinates: [Number] } }); earthquakeSchema.index({ geometry: '2dsphere' }); var Earthquake = mongoose.model('Earthquake', earthquakeSchema); module.exports = Earthquake;
从我的angular度来看,似乎是正确的,但是当我执行它时,我总是得到同样的错误:
[Error: Can't use $near with String.]
我不知道错在哪里。 我已经到处检查了
好吧,我已经find了解决办法:
我必须添加对应于“点”的默认字段到属性“types”。 现在起作用了