关联数组与mongoose模式?

在mongodb中使用关联数组是否被认为是不好的做法? 我很好奇为什么mongoose似乎没有提供这个在它的Schema定义。

如果通过“关联数组”,你的意思是“对象”,这工作正常。 您只能使用普通的旧“对象”,或者您可以指定特定的属性,或者可以使用“mongoose.Schema.Types.Mixed”来允许不同的types。

 { //regular old javascript/json data types created: Date, //this works just fine statistics: Object, //or you can specify the shape of the object address: {state: String, line1: String}, //for the extra features you get with a true subdocument nested: [SomeOtherMongooseSchema], //Could be array, boolean, number, whatever. Can vary with each document. grabBag: mongoose.Schema.Types.Mixed }