mongoose 定义经纬度数据类型

版权声明:转载请评论留言 https://blog.csdn.net/solocao/article/details/83104658

本来想用Double在mongoose中直接定义经纬度的。但是发现mongoose的数据类型只有下面几种。

String
Number
Date
Buffer
Boolean
Mixed
ObjectId
Array
Decimal128
Map

所以我们使用Decimal128来定义经纬度

const LocationsSchema = new mongoose.Schema({
  latitude: {
    type: mongoose.Schema.Types.Decimal128,
    required: true,
  },
  longitude: {
    type: mongoose.Schema.Types.Decimal128,
    required: true,
  }
})

猜你喜欢

转载自blog.csdn.net/solocao/article/details/83104658