mongodb
javascript
node js
5 years, 8 months ago
const mongodb = require("mongodb")
const mongo_client = mongodb.MongoClient
const connUrl = "mongodb://127.0.0.1:27017"
const databaseName = "yourdb"
mongo_client.connect(connUrl,{useNewUrlParser:true}, (error, client)=>{
if(error){
console.log(error)
}
const db = client.db(databaseName)
// Insert One Document
db.collection('users').insertOne({
name: "Kishore",
age: 24
}, (error, res)=>{
if(error){
console.log("Unable to insert")
}
console.log(res.ops)
})
// Insert Many Documents
db.collection('users').insertMany([
{ name: "Kumar", age:25},
{ name: "Raj", age:45}
], (error, res)=>{
if(error){
console.log(error)
}
console.log(res.insertedIds)
})
})
0 Comments
Please Login to Comment Here