我在发布数据更新期间遇到猫鼬错误。错误是:
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
});
Run Code Online (Sandbox Code Playgroud)
后置控制器
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());
});
Run Code Online (Sandbox Code Playgroud)
输出是:
MongoError:无法提取地理键:{_id:ObjectId('5e8c661f274e8e57d8e03887'),geoLocation:{类型:“点”,坐标:[-8.455697300000001,114.5110151],_id:ObjectId('5e8d7f7c35b9d36d45b48 …