借助NodeJS和MongoDB在数据库中存储了Gelo Location

时间:2019-04-10 05:00:16

标签: node.js mongodb mongodb-query

我想使用Mongodb和NodeJS在数据库中存储地理位置

message:
         'Cast to Embedded failed for value "[72.591760, 23.014510]" at path "geometry"',
        name: 'CastError',
        stringValue: '"[72.591760, 23.014510]"',
        kind: 'Embedded',
        value: '[72.591760, 23.014510]',
        path: 'geometry',
        reason: [MongooseError] } },
  _message: 'userLocation validation failed',
  name: 'ValidationError' }

2 个答案:

答案 0 :(得分:0)

以此形式存储位置

 "location_point" : {
    "coordinates" : [ 
        -95.712891, 
        37.09024
    ],
    "type" : "Point"
}

-95.712891 - Long 37.09024 -Lat

答案 1 :(得分:0)

const userLocationData = {
      name,
      geometry: {
        type: 'Point',
        coordinates: JSON.parse(geometry)
      }
    };