#46 Adding MongoDB Database to Codeswear.com | NextJs Tutorial for Beginners #codewithharry
First create the models folder in codeswear.com
under models create three files Order.js , Product.js , User.js
Order.js
// getting-started.js
const mongoose = require('mongoose');
const OrderSchema = new mongoose.Schema({
userId: {type: String, required: true},
products: [{
productsId: {type: String},
quantity: {type: Number, default: 1}
} ],
address: {type: String, required: true},
amount: {type: Number, required: true},
status: {type: String , default: 'Pending', required: true},
}, { timestamps: true});
export default mongoose.model("Order", OrderSchema);
Product.js
// getting-started.js
const mongoose = require('mongoose');
const ProductSchema = new mongoose.Schema({
title: {type: String, required: true},
slug: {type: String, required: true, unique: true},
desc: {type: String, required: true},
img: {type: String, required: true},
category: {type: String, required: true},
size: {type: String},
color: {type: String},
price: {type: Number, required: true},
availableQty: {type: Number, required: true},
}, { timestamps: true});
export default mongoose.model("Product", ProductSchema);
User.js
// getting-started.js
const mongoose = require('mongoose');
const UserSchema = new mongoose.Schema({
Name: {type: String, required: true},
email: {type: String, required: true, unique: true},
password: {type: String, required: true},
}, { timestamps: true});
export default mongoose.model("Product", UserSchema);
Comments
Post a Comment