Adding a User to the Database First, let’s create and record a user to our database. Creating a User Model We've created a user model, which is an object, with a few fields: // models/user.js const mongoose = require('mongoose'); const userSchema = new mongoose.Schema({ email: { type: String, required: true, unique: true }, password: { type: String, required: true, minlength: 8 } }); module.exports = mongoose.model('user', userSchema);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter