An Interest In:
Web News this Week
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
- March 14, 2024
- March 13, 2024
July 13, 2022 05:13 am GMT
Original Link: https://dev.to/himanshupal0001/4-creating-models-for-mongodb-collections-obg
4. Creating models for mongoDb collections
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.
Original Link: https://dev.to/himanshupal0001/4-creating-models-for-mongodb-collections-obg
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To