Schema()

Parameters
  • [definition] «Object|Schema|Array» Can be one of: object describing schema paths, or schema to copy, or array of objects and schemas

  • [options] «Object»

Inherits:

Schema constructor.

Example:

  1. const child = new Schema({ name: String });
  2. const schema = new Schema({ name: String, age: Number, children: [child] });
  3. const Tree = mongoose.model('Tree', schema);
  4. // setting schema options
  5. new Schema({ name: String }, { _id: false, autoIndex: false })

Options:

Options for Nested Schemas:

  • excludeIndexes: bool - defaults to false. If true, skip building indexes on this schema’s paths.

Note:

When nesting schemas, (children in the example above), always declare the child schema first before passing it into its parent.