-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
34 lines (24 loc) · 843 Bytes
/
app.js
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
// refernece to mongodb db
let mongodb = require('mongodb');
//creating instance of mongodb client
let mongodbClient = mongodb.MongoClient;
//connect the server --const is used to protect
const DB_URL = 'mongodb://127.0.0.1:27017';
// In real we dont host db server and backend server togerther
// as there are lot of computations happening
let db;
// connecting to server now
mongodbClient.connect(DB_URL,{
useNewUrlParser:true,
useUnifiedTopology:true
} ,function(err, client)
{
if(err){
console.log('Error in mongodb connection '+err);
}else{
console.log('connection successful');
db = client.db('carsdb'); // this is database
// this is the collection and we are inserting one element at a time
db.collection('newcars').insertOne({maker:'BMW', model: 'x7'});
}
});