使用2d索引,与$geoNear一起使用



我试图使用geoNear与聚合,但我得到这个错误消息:

errmsg: "'near' field must be point"

因为我的location字段是[Number]:

var locationSchema = mongoose.Schema({
name            : String,
addressText     : String,
location    : [Number] // [<longitude>, <latitude>] 
});
module.exports = mongoose.model('Location', locationSchema );

我试着像这样聚集:

Location.aggregate([
            {$geoNear: {
                near: {type : "Point", "location": [ 48.2, 16.3 ]},
                limit: 1000000,
                distanceField: "dist.calculated",
                includeLocs: "true",
                maxDistance: 10
            }}
        ])
        .exec()

我知道我必须添加我的位置type:"Point",但不幸的是太晚了。我能用其他方法解决这个问题吗?

尝试用"coordinates"替换聚合中的"location"

最新更新