Skip to content

Latest commit

 

History

History
19 lines (15 loc) · 821 Bytes

File metadata and controls

19 lines (15 loc) · 821 Bytes

Custom Schema Types

Creating a Basic Custom Schema Type

New in Mongoose 4.4.0: Mongoose supports custom types. Before you reach for a custom type, however, know that a custom type is overkill for most use cases. You can do most basic tasks with custom getters/setters, virtuals, and single embedded docs.

Let's take a look at an example of a basic schema type: a 1-byte integer. To create a new schema type, you need to inherit from mongoose.SchemaType and add the corresponding property to mongoose.Schema.Types. The one method you need to implement is the cast() method.

[require:Creating a Basic Custom Schema Type]