Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 13, 2022 05:13 am GMT

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

Image description

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.

YT link for reference


Original Link: https://dev.to/himanshupal0001/4-creating-models-for-mongodb-collections-obg

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To