从经度和纬度查询时,NodeJs地理问题附近

时间:2018-07-29 11:19:59

标签: node.js mongodb geolocation

此代码有什么问题?我有无法解决的错误:

var d = [
        {
           $geoNear: {
              near : {
                type: 'Point',
                coordinates: [48.3816034, 2.9288093]
              },
              distanceField: 'distance',
              minDistance:0,
              maxDistance: 20000,
              spherical :true
           }
        }
        ,
        {"$lookup":
           {"from":"users","localField":"userId","foreignField":"_id","as":"volontaire"}
        }
     ]

 UserProfile.aggregate(d, (err, results) => console.log(results) )

我的模型的设计如下:

const mongoose = require("mongoose");
var Schema = mongoose.Schema;

var UserSchema = new mongoose.Schema({
   userId:{ type: mongoose.Schema.Types.ObjectId, required: true },
   loc: {
       type: [Number], // [<longitude>, <latitude>]
      index: "2d" // create the geospatial index
   },
});

var UserProfile = mongoose.model('UserProfile', UserSchema);
module.exports = UserProfile;

查询错误输出为:

{"name":"MongoError","message":"geoNear command failed: { ok: 0.0, errmsg: \"error processing query: ns=Lab.userprofiles limit=100Tree: GEONEAR  field=loc maxdist=20000 isNearSphere=1\nSort: {}\nProj: { $pt: { $meta: \"geoNearPoin...\", code: 2, codeName: \"BadValue\" }","ok":0,"errmsg":"geoNear command failed: { ok: 0.0, errmsg: \"error processing query: ns=Lab.userprofiles limit=100Tree: GEONEAR  field=loc maxdist=20000 isNearSphere=1\nSort: {}\nProj: { $pt: { $meta: \"geoNearPoin...\", code: 2, codeName: \"BadValue\" }","code":16604,"codeName":"Location16604"

有人可以帮助我吗?我不知道这个“差值”在哪里

谢谢。

0 个答案:

没有答案