SchemaDocumentArray
SchemaDocumentArray()
SchemaDocumentArray.get()
SchemaDocumentArray.options
SchemaDocumentArray.prototype.discriminator()
SchemaDocumentArray.schemaName
SchemaDocumentArray.set()
SchemaDocumentArray()
參數 (Parameters)
key
«字串 (String)»schema
«模式 (Schema)»options
«物件 (Object)»schemaOptions
«物件 (Object)»
繼承
子文件陣列模式類型建構子
SchemaDocumentArray.get()
參數 (Parameters)
getter
«函式 (Function)»
返回
- «this»
類型
- «屬性 (property)»
為所有 DocumentArrayPath 實例附加 getter
SchemaDocumentArray.options
類型
- «屬性 (property)»
所有文件陣列的選項。
castNonArrays
:預設為true
。如果為false
,當值不是陣列時,Mongoose 將拋出 CastError。如果為true
,Mongoose 將在轉換之前將提供的值包裝在陣列中。
SchemaDocumentArray.prototype.discriminator()
參數 (Parameters)
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({ shapes: [shapeSchema] });
const docArrayPath = parentSchema.path('shapes');
docArrayPath.discriminator('Circle', Schema({ radius: Number }));
SchemaDocumentArray.schemaName
類型
- «屬性 (property)»
此模式類型的名稱,以防止混淆器混淆函式名稱。
SchemaDocumentArray.set()
參數 (Parameters)
option
«字串 (String)» 您要設定的選項名稱(例如,trim、lowercase 等)value
«任意 (Any)» 您要設定的選項值。
返回
- «void,void»
類型
- «屬性 (property)»
為所有 DocumentArray 實例設定預設選項。
範例
// Make all numbers have option `min` equal to 0.
mongoose.Schema.DocumentArray.set('_id', false);