-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongoclient.js
More file actions
38 lines (33 loc) · 1.09 KB
/
mongoclient.js
File metadata and controls
38 lines (33 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// var MongoClient = require('mongodb').MongoClient;
// var url = "mongodb://localhost:27017";
// MongoClient.connect(url, function(err, db) {
// if (err) throw err;
// var dbo = db.db("institueDb");
// var myobj = { id: "3", name: "ravi","class":"11th" };
// dbo.collection("student").insert(myobj, function(err, res) {
// if (err) throw err;
// console.log("1 document inserted");
// db.close();
// });
// });
var MongoClient=require('mongodb').MongoClient
var url ="mongodb://localhost:27017"
MongoClient.connect(url,function(error,db){
if(error) throw error
else
console.log("connected to the database")
var dbo=db.db("retail")
dbo.collection("custumer").insert({"id":"4","name":"priyanshu","custumertype":"regular","address":"hinjewadi"})
console.log("database created")
if (error)
{
console.log("error"+error)
throw error
}
else
{
console.log(" collection custumer created and inserted the information")
}
data=dbo.collection("custumer").find()
console.log(data)
})