Data types allowed in schemas
There are eight types of data that can—by default—be set in a Mongoose schema. These are also referred to as SchemaTypes; they are:
- String
- Number
- Date
- Boolean
- Buffer
- ObjectId
- Mixed
- Array
The first four SchemaTypes are self-explanatory, but let's take a quick look at them all.
String
This SchemaType stores a string value, UTF-8 encoded.
Number
This SchemaType stores a number value, with restrictions. Mongoose does not natively support long
and double
datatypes for example, although MongoDB does. However, Mongoose can be extended using plugins to support these other types. See Chapter 11, Plugins – Re-using Code for more on plugins.
Date
This SchemaType holds a date and time object, typically returned from MongoDB as an ISODate object, ...
Get Mongoose for Application Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.