Это сообщение об ошибке:
ReferenceError: база данных не определена в / Users / dspatiyal / Desktop / Mon go DB / index. js: 12: 21 в / usr /local/lib/node_modules/mongodb/lib/utils.js:731:5
Это код:
var MongoClient= require("mongodb").MongoClient;
var url="mongodb://localhost:27017/employees";
MongoClient.connect(url, function(err,db){
if(err){
console.log("Error Creating Connection");
return
}
console.log("Database Created Successfully..")
var myDatabase= database.db("employees");
myDatabase.createCollection("employeeList",function(err,res){
if(err){
console.log("Error Creating Connection");
return;
}
var employeeListCollection=myDatabase.collection("employeeList")
employeeListCollection.insertOne({
name:"Utkarsh",
age:10
},function(err ,success){
if(err){
console.log("Error Creating Connection");
return;
}
employeeListCollection.find({name:"Mayank"}).toArray(function(err,result){
console.dir(result);
database.close();
})
employeeListCollection.deleteOne,({name:"Mayank"},function(err,obj){
console.log("Object Deleted...")
database.close();
})
employeeListCollection.updateOne({name: "Utkarsh"},{$set :{age:1000}},function(err,result){
database.close();
})
console.log("Document Added to database collection");
})
})
})