diff --git a/dbConnFile.js b/dbConnFile.js index 9c7fa94..5a92a4b 100644 --- a/dbConnFile.js +++ b/dbConnFile.js @@ -12,3 +12,4 @@ async function dbConnect(){ } module.exports = dbConnect; + diff --git a/insert.js b/insert.js new file mode 100644 index 0000000..d96f212 --- /dev/null +++ b/insert.js @@ -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(); + diff --git a/update.js b/update.js new file mode 100644 index 0000000..4af3ee1 --- /dev/null +++ b/update.js @@ -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(); +