与猫鼬模式关联的数组? [英] Associative array with mongoose schema?
本文介绍了与猫鼬模式关联的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在mongodb中使用关联数组是否被认为是不好的做法?我很好奇为什么猫鼬似乎没有在其Schema定义中提供此功能.
Is it considered bad practice to use associative arrays in mongodb? I'm curious as to why mongoose doesn't seem to provide this in its Schema definition.
推荐答案
如果使用关联数组",则表示对象",可以正常工作.您可以只使用常规的旧对象",也可以指定特定的属性,也可以使用"mongoose.Schema.Types.Mixed"来允许各种类型.
If by "associative array", you mean "Object", that works fine. You can use just regular old "Object" or you can specify specific properties or you can use "mongoose.Schema.Types.Mixed" to allow varying 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
}
这篇关于与猫鼬模式关联的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文