【问题标题】:MongoError : Can't project geometry into spherical CRSMongoError:无法将几何投影到球形 CRS
【发布时间】:2017-08-03 11:12:07
【问题描述】:

我正在尝试在 Mongo 中存储实体的位置。我似乎只对输入的几个位置有问题。我得到的错误是

MongoError:无法提取地理键:无法将几何投影到球形 CRS:[26.1633829, 91.78194759999997]。是不是索引有问题。我正在开发 mongodb 3.4 版

我的架构如下

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var modelSchema = new mongoose.Schema({

email: {type: String, lowercase: true},
username: {type: String, unique: true, lowercase: true, index: true},
branchName: String,
address: {
    address1: String,
    address2: String,
    locality: String,
    pinCode: Number,
    sublocality_level_2: String,
    sublocality_level_1: String,
    localityName: String,
    administrative_area_level_2: String,
    administrative_area_level_1: String,
    country: String,
    postal_code: String,
    geo: {
        type: [Number],
        index: '2dsphere'
    }
},
branchPAN: String,
branchType: String,        
});

module.exports = mongoose.model('SampleModel', modelSchema);

【问题讨论】:

    标签: node.js mongodb mongoose geospatial


    【解决方案1】:

    我不是 100% 确定,但我认为您的问题来自点的类型。如果您查看文档,它说您应该将 GeoJSON 用于 2dsphere。

    2dsphere 索引支持将数据存储为 GeoJSON 对象和 旧坐标对(另请参见 2dsphere 索引字段 限制)。对于传统坐标对,索引将 数据到 GeoJSON 点。有关支持的 GeoJSON 对象的详细信息, 请参阅 GeoJSON 对象。

    您应该使用以下格式,而不是单个数字数组:

    { type: "<GeoJSON type>" , coordinates: <coordinates> }
    

    为此有一个猫鼬插件:mongoose-geojson-schema

    【讨论】:

    • 非常感谢您的帮助。
    【解决方案2】:

    在这里阅读更多内容后。 https://docs.mongodb.com/manual/reference/geojson/#point

    该链接中有注释

    重要 始终按经度、纬度顺序列出坐标。

    我以相反的方式传递值。

    【讨论】:

      猜你喜欢
      • 2021-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-09
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      • 2012-10-30
      相关资源
      最近更新 更多