From ddabb1187f8e350ec05684c0c2beb2830e7d70a3 Mon Sep 17 00:00:00 2001 From: Andrew Molchanov Date: Fri, 27 Nov 2020 02:23:47 +0300 Subject: [PATCH] Changes to support MongoDB Node.JS Driver v3 --- lib/document_stores/{mongo.js => mongodb.js} | 21 ++++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) rename lib/document_stores/{mongo.js => mongodb.js} (81%) diff --git a/lib/document_stores/mongo.js b/lib/document_stores/mongodb.js similarity index 81% rename from lib/document_stores/mongo.js rename to lib/document_stores/mongodb.js index 502a508..e700212 100644 --- a/lib/document_stores/mongo.js +++ b/lib/document_stores/mongodb.js @@ -1,21 +1,20 @@ - - -var MongoClient = require('mongodb').MongoClient, +const MongoClient = require('mongodb').MongoClient, winston = require('winston'); -var MongoDocumentStore = function (options) { +const MongoDocumentStore = function (options) { this.expire = options.expire; - this.connectionUrl = process.env.DATABASE_URl || options.connectionUrl; + this.connectionUrl = process.env.DATABASE_URL || options.connectionUrl; + this.connectionName = process.env.DATABASE_NAME || options.connectionName; }; MongoDocumentStore.prototype.set = function (key, data, callback, skipExpire) { - var now = Math.floor(new Date().getTime() / 1000), + const now = Math.floor(new Date().getTime() / 1000), that = this; this.safeConnect(function (err, db) { if (err) return callback(false); - + db.collection('entries').update({ 'entry_id': key, $or: [ @@ -40,13 +39,13 @@ MongoDocumentStore.prototype.set = function (key, data, callback, skipExpire) { }; MongoDocumentStore.prototype.get = function (key, callback, skipExpire) { - var now = Math.floor(new Date().getTime() / 1000), + const now = Math.floor(new Date().getTime() / 1000), that = this; this.safeConnect(function (err, db) { if (err) return callback(false); - + db.collection('entries').findOne({ 'entry_id': key, $or: [ @@ -75,12 +74,12 @@ MongoDocumentStore.prototype.get = function (key, callback, skipExpire) { }; MongoDocumentStore.prototype.safeConnect = function (callback) { - MongoClient.connect(this.connectionUrl, function (err, db) { + MongoClient.connect(this.connectionUrl, function (err, client) { if (err) { winston.error('error connecting to mongodb', { error: err }); callback(err); } else { - callback(undefined, db); + callback(undefined, client.db(this.connectionDBName)); } }); };