SchemaSubdocument
SchemaSubdocument()SchemaSubdocument.get()SchemaSubdocument.prototype.discriminator()SchemaSubdocument.set()
SchemaSubdocument()
参数
schema«Schema»path«String»options«Object»
继承
单个嵌套子文档 SchemaType 构造函数。
SchemaSubdocument.get()
参数
getter«Function»
返回值
- «this»
类型
- «property»
为所有子文档实例附加一个获取器
SchemaSubdocument.prototype.discriminator()
参数
name«String»schema«Schema» 要添加到此子类实例模式中的字段[options]«Object|string» 如果是字符串,与options.value相同。[options.value]«String» 存储在discriminatorKey属性中的字符串。如果未指定,Mongoose 使用name参数。[options.clone=true]«Boolean» 默认情况下,discriminator()克隆给定的schema。设置为false以跳过克隆。
返回值
- «Function» Mongoose 用于创建此鉴别器模型实例的构造函数
参见
向此单个嵌套子文档添加鉴别器。
示例
const shapeSchema = Schema({ name: String }, { discriminatorKey: 'kind' });
const schema = Schema({ shape: shapeSchema });
const singleNestedPath = parentSchema.path('shape');
singleNestedPath.discriminator('Circle', Schema({ radius: Number })); SchemaSubdocument.set()
参数
option«String» 您要设置值的选项value«Any» 选项的值
返回值
- «void,void»
类型
- «property»
为所有子文档实例设置默认选项。
示例
// Make all numbers have option `min` equal to 0.
mongoose.Schema.Subdocument.set('required', true); 
