SchemaDocumentArray
SchemaDocumentArray()SchemaDocumentArray.get()SchemaDocumentArray.optionsSchemaDocumentArray.prototype.$conditionalHandlersSchemaDocumentArray.prototype.discriminator()SchemaDocumentArray.prototype.toJSONSchema()SchemaDocumentArray.schemaNameSchemaDocumentArray.set()
SchemaDocumentArray()
Parameters:
key«String»schema«Schema»options«Object»schemaOptions«Object»
Inherits:
SubdocsArray SchemaType constructor
SchemaDocumentArray.get()
Parameters:
getter«Function»
Returns:
- «this»
Type:
- «property»
Attaches a getter for all DocumentArrayPath instances
SchemaDocumentArray.options
Type:
- «property»
Options for all document arrays.
castNonArrays:trueby default. Iffalse, Mongoose will throw a CastError when a value isn't an array. Iftrue, Mongoose will wrap the provided value in an array before casting.
SchemaDocumentArray.prototype.$conditionalHandlers
Type:
- «property»
Contains the handlers for different query operators for this schema type.
For example, $conditionalHandlers.$size is the function Mongoose calls to cast $size filter operators.
SchemaDocumentArray.prototype.discriminator()
Parameters:
name«String»schema«Schema» fields to add to the schema for instances of this sub-class[options]«Object|string» If string, same asoptions.value.[options.value]«String» the string stored in thediscriminatorKeyproperty. If not specified, Mongoose uses thenameparameter.[options.clone=true]«Boolean» By default,discriminator()clones the givenschema. Set tofalseto skip cloning.
Returns:
- «Function» the constructor Mongoose will use for creating instances of this discriminator model
See:
Adds a discriminator to this document array.
Example:
const shapeSchema = Schema({ name: String }, { discriminatorKey: 'kind' });
const schema = Schema({ shapes: [shapeSchema] });
const docArrayPath = parentSchema.path('shapes');
docArrayPath.discriminator('Circle', Schema({ radius: Number })); SchemaDocumentArray.prototype.toJSONSchema()
Parameters:
[options]«»[options.useBsonType=false]«» If true, return a representation withbsonTypefor use with MongoDB's$jsonSchema.
Returns this schema type's representation in a JSON schema.
SchemaDocumentArray.schemaName
Type:
- «property»
This schema type's name, to defend against minifiers that mangle function names.
SchemaDocumentArray.set()
Parameters:
option«String» The name of the option you'd like to set (e.g. trim, lowercase, etc...)value«Any» The value of the option you'd like to set.
Returns:
- «void,void»
Type:
- «property»
Sets a default option for all DocumentArray instances.
Example:
// Make all numbers have option `min` equal to 0.
mongoose.Schema.DocumentArray.set('_id', false); 