-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
41 lines (35 loc) · 976 Bytes
/
database.js
File metadata and controls
41 lines (35 loc) · 976 Bytes
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
const mongo =require('mongodb').MongoClient;
const url='mongodb://localhost:27017';
const dbName = 'shopping';
let shopping;
function Connection(){
mongo.connect(url,function (err,client) {
shopping =client.db(dbName);
})
}
function Insertdocs(cb){
const collection = shopping.collection('documents')
collection.insertMany([
{a : 1}, {a : 2}, {a : 3}
], function(err, result){
findDocs(function (data) {
cb(data)
})
})
}
function findDocs(cb){
const collection = shopping.collection('documents');
collection.find({}).toArray(function (err,result) {
cb(result);
})
}
function delDocs(cb){
const collection = shopping.collection('documents');
collection.deleteMany([{ a : 1 },{ a : 2 },{ a : 3 }], function(err, result){
console.log("Removed the document with the field a equal to 3");
callback(result);})
}
module.exports ={
Connection,
Insertdocs
};