Today we'll see How to create model for mongoDB in js.
Create a folder name models in vscode directory.
Create a file 'Users.js' as we prefer capital latter for models.
Below is the ss of directory
const mongoose = require('mongoose');
const UserSchema = mongoose.Schema({
name: {
type: String,
required: true,
},
email: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true,
},
avatar: {
type: String,
},
date: {
type: Date,
default: Date.now
}
})
module.exports = User = mongoose.model('user', UserSchema);
We have used mongoose as a lib for mongoDb.
Top comments (0)