MongoError:无法提取地理键 [英] MongoError: Can't extract geo keys

查看:53
本文介绍了MongoError:无法提取地理键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在发布数据更新期间遇到猫鼬错误.错误是:

I'm facing a mongoose error during post data updation. The error is:

MongoError:无法提取地理键

MongoError: Can't extract geo keys

我试图通过在谷歌上搜索来找到原因和解决方案,但仍然没有得到任何适当的解决方案.

I've tried to find the reason and the solution by searching on google but still I didn't get any proper solution.

帖子模型

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:{类型:点",坐标:[-8.455697300000001,114.5110156d}3b'4b'7d3b'7d3d}3b'7d'7d38d38dc无法将几何投影到球形 CRS 中:[ -8.455697300000001, 114.5110151 ]

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 ]

推荐答案

一个名为坐标的字段,用于指定对象的坐标.

a field named coordinates that specifies the object’s coordinates.

如果指定经纬度坐标,先列出经度再列出纬度:

If specifying latitude and longitude coordinates, list the longitude first and then latitude:

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

Valid longitude values are between -180 and 180, both inclusive. Valid latitude values are between -90 and 90, both inclusive.

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

Which means this takes longitude at index 0 and latitude at index 1.

试试坐标:[ 114.5110151,-8.4556973] }

这篇关于MongoError:无法提取地理键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆