-
Notifications
You must be signed in to change notification settings - Fork 2
/
mongo.js
38 lines (29 loc) · 831 Bytes
/
mongo.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
const mongodb = require('mongodb');
const MongoClient = mongodb.MongoClient;
const connectionURL = process.env.MONGODB_URI;
const databaseName = process.env.MONGODB_DATABASE;
const collection_name = process.env.MONGODB_COLLECTION;
var dbo;
var collection;
try {
MongoClient.connect(connectionURL, {useNewUrlParser: true, useUnifiedTopology: true, poolSize:10}, async (err, db) => {
try {
dbo = db.db(databaseName);
collection = dbo.collection(collection_name)
}catch (e1) {
console.log(e1)
}
});
}catch (e) {
console.log(e);
}
function MongoLogger() {
}
MongoLogger.prototype.sendMessage = async function(message) {
try {
collection.insertOne(message);
}catch (e) {
console.log(e)
}
};
module.exports = new MongoLogger();