Member-only story
Using MongoDB with Mongoose — String, Number, and Date Schema Types
3 min readJan 14, 2021
To make MongoDB database manipulation easy, we can use the Mongoose NPM package to make working with MongoDB databases easier.
In this article, we’ll look at how to use Mongoose to manipulate our MongoDB database.
String Schema Types
We can set various properties for strings schema types.
They include:
lowercase
: boolean, whether to always call.toLowerCase()
on the valueuppercase
: boolean, whether to always call.toUpperCase()
on the valuetrim
: boolean, whether to always call.trim()
on the valuematch
: RegExp, creates a validator that checks if the value matches the given regular expressionenum
: Array, creates a validator that checks if the value is in the given array.minlength
: Number, creates a validator that checks if the value length is not less than the given numbermaxlength
: Number, creates a validator that checks if the value length is not greater than the given number
For example, we can write:
const mongoose = require('mongoose');
const connection = "mongodb://localhost:27017/test"…