-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathapp.js
46 lines (33 loc) · 1.08 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
//connect nodejs to mongo db
const assert = require('assert');
const MongoDao = require('./mongodao');
const url = 'mongodb://nagappans:abc123@localhost:27017/?authMechanism=DEFAULT';
const dbName = 'ecommerce';
const collectionName = "customer";
var doc = {"firstName":"nagappan","lastName":"subramanian","emailId":"[email protected]"};
var mongoDao;
const readFn = function() {
mongoDao.readCollection(collectionName).toArray(function(err, docs) {
console.log(docs.length + " documents available in collection "+ collectionName + " \n");
insertFn();
});
}
const insertFn = function() {
//insert and then inserted record will be read
mongoDao.insertDocument(collectionName, doc, updateFn);
}
const updateFn = function() {
var updateDoc = {"$set": {"mobile": 9629230494}};
mongoDao.updateDocument(collectionName, doc, updateDoc, deleteFn);
}
const deleteFn = function() {
mongoDao.deleteDocument(collectionName, doc, endProgram);
}
const endProgram = function() {
process.exit(0);
}
async function main() {
mongoDao = await new MongoDao(url, dbName);
insertFn();
}
main();