deno.land / x / mongoose@6.7.5 / docs / customschematypes.md

customschematypes.md

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]
mongoose

Version Info

Tagged at
a year ago