DocumentArrayPath

DocumentArrayPath()

Parameters
  • key «String»
  • schema «Schema»
  • options «Object»
Inherits:
  • «SchemaArray»

SubdocsArray SchemaType constructor


DocumentArrayPath.options

Type:
  • «property»

Options for all document arrays.

  • castNonArrays: true by default. If false, Mongoose will throw a CastError when a value isn’t an array. If true, Mongoose will wrap the provided value in an array before casting.

DocumentArrayPath.prototype.discriminator()

Parameters
  • name «String»
  • schema «Schema» fields to add to the schema for instances of this sub-class

  • [value] «String» the string stored in the discriminatorKey property. If not specified, Mongoose uses the name parameter.

Returns:
  • «Function» the constructor Mongoose will use for creating instances of this discriminator model

Adds a discriminator to this document array.

Example:

  1. const shapeSchema = Schema({ name: String }, { discriminatorKey: 'kind' });
  2. const schema = Schema({ shapes: [shapeSchema] });
  3. const docArrayPath = parentSchema.path('shapes');
  4. docArrayPath.discriminator('Circle', Schema({ radius: Number }));

DocumentArrayPath.schemaName

Type:
  • «property»

This schema type’s name, to defend against minifiers that mangle function names.


function Object() { [native code] }.

Parameters
  • option «String»
    • The option you’d like to set the value for
  • value «*»
    • value for option
Returns:
  • «undefined»
Type:
  • «property»

Sets a default option for all DocumentArray instances.

Example:

  1. // Make all numbers have option `min` equal to 0.
  2. mongoose.Schema.DocumentArray.set('_id', false);