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

前端 未结 5 1587
清酒与你
清酒与你 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:05

    Maybe it is too late, but here mongoose is assuming that deviceId is not an object and it is of type String

    deviceId: {
      type : String,
      index : {
        unique : true,
        dropDups : true
      }
    },
    

    SIMPLE SOLUTION:

    deviceId: {
      type: {
        type: String
      },
      index: {
        unique: true,
        dropDups: true
      }
    },
    

提交回复
热议问题