Schema.prototype.add()

Parameters
  • obj «Object|Schema» plain object with paths to add, or another schema

  • [prefix] «String» path to prefix the newly added paths with

Returns:
  • «Schema» the Schema instance

Adds key path / schema type pairs to this schema.

Example:

  1. const ToySchema = new Schema();
  2. ToySchema.add({ name: 'string', color: 'string', price: 'number' });
  3. const TurboManSchema = new Schema();
  4. // You can also `add()` another schema and copy over all paths, virtuals,
  5. // getters, setters, indexes, methods, and statics.
  6. TurboManSchema.add(ToySchema).add({ year: Number });