Mongoose, CastError: Cast to Array failed for value when trying to save a model that contains a model

后端 未结 7 1529
日久生厌
日久生厌 2020-12-09 14:52

I am trying to create the model for my mongodb database using mongoose. This is what I am trying to do:

var Class = mongoose.model(\'Class\', {className: St         


        
7条回答
  •  囚心锁ツ
    2020-12-09 15:33

    Just for Update

    Now Mongoose supports subdocuments, which are the documented way to nest arrays,

    var arraySchema = new Schema({
        property: String
    });
    
    var objectSchema = new Schema({
        arrays: [arraySchema]
    });
    

    Sources

    http://mongoosejs.com/docs/schematypes.html

提交回复
热议问题