【发布时间】:2020-07-20 14:18:47
【问题描述】:
我在发布数据更新期间遇到猫鼬错误。 错误是:
MongoError:无法提取地理键
我已经尝试通过谷歌搜索找到原因和解决方案,但我仍然没有得到任何合适的解决方案。
帖子模型
const geoLocationSchema = new mongoose.Schema({
type: { type: String, default: 'Point'},
coordinates: {
type: [Number],
index: { type: '2dsphere', sparse: false },
}
});
const postsSchema = new mongoose.Schema({
post_title: String,
geoLocation: geoLocationSchema,
}, {
timestamps: true
});
后控制器
const Posts = require("../models/Posts");
var findPattern = {_id: "5e8c661f274e8e57d8e03887"};
var updatePattern = { geoLocation: {
type: "Point",
coordinates: [-8.4556973, 114.5110151] }
};
Posts.updateOne(findPattern, updatePattern) .then(updateRes => {
console.log("post updated");
}).catch(err => {
console.log("error", err.toString());
});
输出为:
MongoError: 无法提取地理键:{ _id: ObjectId('5e8c661f274e8e57d8e03887'), geoLocation: { type: "Point", 坐标: [-8.455697300000001, 114.5110151], _id: ObjectId('5e8d7f7c35b9d36d45b4)8无法将几何投影到球形 CRS:[-8.455697300000001, 114.5110151]
【问题讨论】:
-
检查您的纬度值,它们似乎超出范围。
-
@mehta-rohan Lat long 是正确的。这是给印度尼西亚巴厘岛的。