SchemaDocumentArray
SchemaDocumentArray()SchemaDocumentArray.get()SchemaDocumentArray.optionsSchemaDocumentArray.prototype.discriminator()SchemaDocumentArray.schemaNameSchemaDocumentArray.set()
SchemaDocumentArray()
参数
key«字符串»schema«模式»options«对象»schemaOptions«对象»
继承
SubdocsArray SchemaType 构造函数
SchemaDocumentArray.get()
参数
getter«函数»
返回值
- «this»
类型
- «属性»
为所有 DocumentArrayPath 实例附加 getter
SchemaDocumentArray.options
类型
- «属性»
所有文档数组的选项。
castNonArrays:默认情况下为true。如果为false,Mongoose 会在值不是数组时抛出 CastError。如果为true,Mongoose 会在转换前将提供的 value 包装在一个数组中。
SchemaDocumentArray.prototype.discriminator()
参数
name«字符串»schema«模式» 要添加到此子类的实例模式中的字段[options]«对象 | 字符串» 如果是字符串,与options.value相同。[options.value]«字符串» 存储在discriminatorKey属性中的字符串。如果没有指定,Mongoose 将使用name参数。[options.clone=true]«布尔值» 默认情况下,discriminator()会克隆给定的schema。设置为false跳过克隆。
返回值
- «函数» Mongoose 将用于创建此鉴别器模型实例的构造函数
参见
向此文档数组添加鉴别器。
示例
const shapeSchema = Schema({ name: String }, { discriminatorKey: 'kind' });
const schema = Schema({ shapes: [shapeSchema] });
const docArrayPath = parentSchema.path('shapes');
docArrayPath.discriminator('Circle', Schema({ radius: Number })); SchemaDocumentArray.schemaName
类型
- «属性»
此模式类型的名称,以防御混淆函数名的缩小器。
SchemaDocumentArray.set()
参数
option«字符串» 您要设置的选项名称(例如 trim、lowercase 等...)value«任何» 您要设置的选项的值。
返回值
- «void,void»
类型
- «属性»
为所有 DocumentArray 实例设置默认选项。
示例
// Make all numbers have option `min` equal to 0.
mongoose.Schema.DocumentArray.set('_id', false); 
