Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (50.2k points)

Is the below schema represented correctly or does the script need to be writing: [Schema.Types.Mixed] or writing: [{}]?

What I mean if you have an array of dictionaries -- [{},{},{}] -- one can't predefine the inner structure unless you create another schema and embed it. Is that the right analysis of the docs?

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

var blogSchema = new mongoose.Schema({

  title:  String,

  writing: [{

        post: String,

        two: Number,

        three : Number,

        four  : String,

        five : [{  a: String,

                    b : String,

                    c  : String,

                    d: String,

                    e: { type: Date, default: Date.now }, 

                }]

  }],

});

1 Answer

0 votes
by (108k points)
edited by

Yes, your structure is accurate. Stating an object within an array schema/structure element is considered as its Schema object. With that being said, the schema object will have their individual id field, but you can disable those id fields by explicitly defining the schema with the _id option being disabled:

var blogSchema = new mongoose.Schema({title: String, writing: [new Schema({post: String, two: Number, three : Number, four  : String, five : [new Schema({ a: String, b: String, c: String, d: String, e: { type: Date, default: Date.now }, }, {_id: false})], {_id: false})], });

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...