SchemaSubdocument


SchemaSubdocument()

參數
  • schema «Schema»
  • path «String»
  • options «Object»
繼承

單一巢狀子文件 SchemaType 建構子。


SchemaSubdocument.get()

參數
  • getter «Function»
回傳
  • «this»
類型
  • «property»

為所有子文件實例附加一個 getter


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);