Mongoose Schema Error: “Cast to string failed for value” when pushing object to empty array

前端 未结 5 1588
清酒与你
清酒与你 2020-12-17 15:32

I have a strange problem and cannot figure out what the problem is. The Error-message doesn\'t help.

I\'m sending an "alarm" to the server and want to save

5条回答
  •  粉色の甜心
    2020-12-17 16:07

    var deviceSchema = new Schema({
     deviceId: {
        type : String,
        index : {
            unique : true,
            dropDups : true
        },
        alarms : {type: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Alarm' }]}
    });
    
    var alarmSchema = new Schema({
        timestamp : Number,
        dateTime : String, //yyyymmddhhss
        difference : Number,
        actionTaken : String, //"send sms"
    });
    

    I would recommend to make an own schema for the alarms. I think u cant define an array in a schema like you do.

提交回复
热议问题