无法提取地理位置键

时间:2018-11-02 06:17:10

标签: node.js mongodb express mongoose postman

我正在尝试将位置存储在MongoDB数据库中。到目前为止,我创建了一个包含字段的模式-

lastLocation: {
type: [Number, Number],
index: '2dsphere'
}, 

因此,当我尝试使用邮递员对值进行充气时,所有其他字段都存储在数据库中,但位置未存储。

我尝试发送下面给出的原始数据-

{ ...."lastLocation": [123.443,123.342],.....}

并出现以下错误-

can\'t project geometry into spherical CRS: [ 123.443,123.342 ]

我想要我可以在邮递员中发送的虚拟数据作为原始数据。那么,有人可以给我原始数据吗?还请提出我在nodejs代码的其他部分是否也错了。我在这里用猫鼬。

谢谢

1 个答案:

答案 0 :(得分:0)

尝试这些更改。可能会对您有帮助。

const location = {
    lastLocation: {
        type: {
            type: String,
            default: 'Point'
        },
        coordinates: []
    }
}
location.index({
    location: '2dsphere'
})