-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.js
33 lines (28 loc) · 1 KB
/
driver.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
/**
* Implementing application to database connection
*/
const configuration = require('./configuration').configuration;
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
//Connection URL
const url = configuration.database.url;
//Database name
const dbName = configuration.database.name;
//Collection name
const collectionName = configuration.database.collection;
//Use connect method to connect to the server
/**
* Method to insert one document into database
*/
module.exports.insertDocument = function(document, callback) {
MongoClient.connect(url, (errorConnection, client) => {
assert.equal(null, errorConnection);
const db = client.db(dbName);
const collection = db.collection(collectionName);
collection.insertOne(document, (errorInsertion, resultInsertion) => {
assert.equal(errorInsertion, null);
client.close();
callback(errorInsertion, resultInsertion);
})
})
}