MongoError: Can't extract geo keys

MongoError: Can't extract geo keys

我在 post 数据更新期间遇到猫鼬错误。 错误是:

MongoError: Can't extract geo keys

我已经尝试在google上搜索找到原因和解决方案,但仍然没有找到任何合适的解决方案。

Posts 型号

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
});

Post 控制器

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: Can't extract geo keys: { _id: ObjectId('5e8c661f274e8e57d8e03887'), geoLocation: { type: "Point", coordinates: [ -8.455697300000001, 114.5110151 ], _id: ObjectId('5e8d7f7c35b9d36d45b483a2') } } can't project geometry into spherical CRS: [ -8.455697300000001, 114.5110151 ]

指定对象坐标的名为坐标的字段。

如果指定纬度和经度坐标,先列出经度,然后列出纬度:

有效的经度值介于 -180 和 180 之间,包括两者。 有效的纬度值介于 -90 和 90 之间,包括两者。

这意味着这需要索引 0 处的经度和索引 1 处的纬度。

尝试coordinates: [ 114.5110151,-8.4556973] }

check this image

注意: userSchema.index({ location: '2dsphere' })