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.]
我不知道錯在哪裏。我已簽到處
我可以知道你是怎麼做到的?你能更新你的答案嗎? –