Skip to content

Commit

Permalink
starting with mongoose(DB connection , Schema and Model)
Browse files Browse the repository at this point in the history
  • Loading branch information
codingXpert committed Jul 30, 2022
1 parent 000cf9d commit a27b2a1
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 0 deletions.
26 changes: 26 additions & 0 deletions mongoose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const mongoose = require("mongoose");

const main = async () => {
await mongoose.connect("mongodb://localhost:27017/e-comm");

//Defining the schema of db
const productSchema = new mongoose.Schema({
name: String,
price: Number,
brand: String,
category: String
});

//defining model for the db
const productModel = mongoose.model("products", productSchema);
let data = new productModel({
name: "m 10",
price: 1000,
brand: "maxx",
category: "mobile",
});
let result = await data.save();
console.log(result);
};

main();
165 changes: 165 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"http": "^0.0.1-security",
"i": "^0.3.7",
"mongodb": "^4.7.0",
"mongoose": "^6.2.9",
"nodemon": "^2.0.18",
"react-toastify": "^9.0.5",
"to": "^0.2.9",
Expand Down

0 comments on commit a27b2a1

Please sign in to comment.