SchemaSubdocument
SchemaSubdocument()SchemaSubdocument.get()SchemaSubdocument.prototype.$conditionalHandlersSchemaSubdocument.prototype.discriminator()SchemaSubdocument.prototype.toJSONSchema()SchemaSubdocument.set()
SchemaSubdocument()
Parameters:
schema«Schema»path«String»options«Object»
Inherits:
Single nested subdocument SchemaType constructor.
SchemaSubdocument.get()
Parameters:
getter«Function»
Returns:
- «this»
Type:
- «property»
Attaches a getter for all Subdocument instances
SchemaSubdocument.prototype.$conditionalHandlers
Type:
- «property»
Contains the handlers for different query operators for this schema type.
For example, $conditionalHandlers.$exists is the function Mongoose calls to cast $exists filter operators.
SchemaSubdocument.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 single nested subdocument.
Example:
const shapeSchema = Schema({ name: String }, { discriminatorKey: 'kind' });
const schema = Schema({ shape: shapeSchema });
const singleNestedPath = parentSchema.path('shape');
singleNestedPath.discriminator('Circle', Schema({ radius: Number })); SchemaSubdocument.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.
SchemaSubdocument.set()
Parameters:
option«String» The option you'd like to set the value forvalue«Any» value for option
Returns:
- «void,void»
Type:
- «property»
Sets a default option for all Subdocument instances.
Example:
// Make all numbers have option `min` equal to 0.
mongoose.Schema.Subdocument.set('required', true); 