理解mongoose

是否正确定义了下面的模式,或者writing是否需要writing: [Schema.Types.Mixed] 或者 writing: [{}]

也就是说,如果您有一组词典 – [{},{},{}] – 除非您创build另一个模式并embedded它,否则不能预定义内部结构。 这是对文档的正确解释吗?

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 }, }] }], }); 

谢谢。

这个模式很好。 在数组模式元素中定义对象被隐式地视为其自己的Schema对象。 因此,他们将拥有自己的_id字段,但是可以通过禁用_id选项显式定义架构来禁用该字段:

 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})], });