Skip to content

Commit

Permalink
insertimg and updating record indb
Browse files Browse the repository at this point in the history
  • Loading branch information
codingXpert committed Jul 12, 2022
1 parent 53dc7fc commit 410a4e0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions dbConnFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ async function dbConnect(){
}

module.exports = dbConnect;

23 changes: 23 additions & 0 deletions insert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const dbConnect = require('./dbConnFile');

const insert = async()=>{
const db = await dbConnect();
const result = await db.insert(
[
{name:'max 1' , brand:'micromax' , price:'220' , category:'mobile' },
{name:'max 2' , brand:'micromax' , price:'320' , category:'mobile' },
{name:'max 3' , brand:'micromax' , price:'420' , category:'mobile' }
]
);

if(result.acknowledged){
console.log("Data inserted");
}

else{
console.log("Error!!!!!");
}
}

insert();

24 changes: 24 additions & 0 deletions update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const dbConnect = require("./dbConnFile");

const updateData = async () => {
let data = await dbConnect();
let result = await data.updateOne(
{ name: "max 1" },
{ $set: { name: "max pro", price: 550 } }
);


//Update/modify all record having name max 1
// let data = dbConnect();
// let result = data.update(
// { name: "max 1" },
// { $set: { name: "max pro", price: 550 } }
// );
console.log(result);
if(result.acknowledged){
console . log('******Record updated*******');
}
}

updateData();

0 comments on commit 410a4e0

Please sign in to comment.