我使用geonear的nodejs应用程序出现错误,如果有人可以帮助我,我将不理解输出错误:
{
"error": {
"name": "MongoError",
"message": "geoNear command failed: { ok: 0.0, errmsg: \"error processing query: ns=Lab.userprofiles limit=100Tree: GEONEAR field=loc maxdist=2000 isNearSphere=1\nSort: {}\nProj: { $pt: { $meta: \"geoNearPoint...\", 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=2000 isNearSphere=1\nSort: {}\nProj: { $pt: { $meta: \"geoNearPoint...\", code: 2, codeName: \"BadValue\" }",
"code": 16604,
"codeName": "Location16604"
}
}
下面是集合的架构:
const mongoose = require("mongoose");
var Schema = mongoose.Schema;
var UserSchema = new mongoose.Schema({
userId:{ type: mongoose.Schema.Types.ObjectId, ref: "User"},
picture : String,
telephone: {
type: String,
unique: false
},
adresse:String,
loc: {
type: [Number], // [<longitude>, <latitude>]
index: "2d" // create the geospatial index
},
sexe:String,
metier:String,
age:{ type : Array , "default" : [] },
centreInterets:{ type : Array , "default" : [] },
pays:String,
ville:String,
code_postal:Number,
nom: String,
prenom:String,
status:String
});
var UserProfile = mongoose.model('UserProfile', UserSchema);
module.exports = UserProfile;
最后是查询:
exports.findVolontaires = (req, res, next) => {
UserProfile.aggregate (
[{
$geoNear: {
near : {
type: "Point",
coordinates: [-95.9953, 41.2000]
},
distanceField: "dist",
maxDistance: 2000,
spherical :true
}
}]
, (err, results) => {
if( err ) {
return res.status(200).json({
error : err
})
}
return res.status(200).json({
results : results
})
}
)
}
感谢您的帮助,我已经尝试在mongodb文档中搜索解决方案,并在错误中使用Google搜索成功。