How to add data to array in Mongoose Schema

前端 未结 1 2070
粉色の甜心
粉色の甜心 2020-12-22 09:16

Assuming the following schema, I am trying to save some GeoJSON data with Mongoose

var simpleSchema = new Schema({
    properties:{
        name:String,
         


        
相关标签:
1条回答
  • 2020-12-22 10:01

    When using a field named type in an embedded object, you need to use an object to define its type or Mongoose thinks you're defining the type of object itself.

    So change your schema definition to:

    var simpleSchema = new Schema({
        properties:{
            name:String,
            surname:String
        },
        location : {
            type : { type: String },
            coordinates : [ Number , Number ]
        }
    });
    
    0 讨论(0)
提交回复
热议问题