2015-05-05 104 views
1

这是一个对象,例如:

{ 
    "_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); 
      }) 

,这是我所创建的模型架构:

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; 

从我的角度来看,它似乎是正确的,但是当我执行它时,我总是得到相同的错误:

[Error: Can't use $near with String.] 

我不知道错在哪里。我已签到处

回答

1

好,我已经找到了解决办法:

我要补充相应的“点”财产“类型”默认域。现在它可以工作

+0

我可以知道你是怎么做到的?你能更新你的答案吗? –