mirror of
https://github.com/seejohnrun/haste-server.git
synced 2024-11-01 11:31:22 +00:00
Changes to support MongoDB Node.JS Driver v3
This commit is contained in:
parent
5d2965ffc5
commit
ddabb1187f
1 changed files with 10 additions and 11 deletions
|
@ -1,15 +1,14 @@
|
||||||
|
const MongoClient = require('mongodb').MongoClient,
|
||||||
|
|
||||||
var MongoClient = require('mongodb').MongoClient,
|
|
||||||
winston = require('winston');
|
winston = require('winston');
|
||||||
|
|
||||||
var MongoDocumentStore = function (options) {
|
const MongoDocumentStore = function (options) {
|
||||||
this.expire = options.expire;
|
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) {
|
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;
|
that = this;
|
||||||
|
|
||||||
this.safeConnect(function (err, db) {
|
this.safeConnect(function (err, db) {
|
||||||
|
@ -40,7 +39,7 @@ MongoDocumentStore.prototype.set = function (key, data, callback, skipExpire) {
|
||||||
};
|
};
|
||||||
|
|
||||||
MongoDocumentStore.prototype.get = function (key, 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;
|
that = this;
|
||||||
|
|
||||||
this.safeConnect(function (err, db) {
|
this.safeConnect(function (err, db) {
|
||||||
|
@ -75,12 +74,12 @@ MongoDocumentStore.prototype.get = function (key, callback, skipExpire) {
|
||||||
};
|
};
|
||||||
|
|
||||||
MongoDocumentStore.prototype.safeConnect = function (callback) {
|
MongoDocumentStore.prototype.safeConnect = function (callback) {
|
||||||
MongoClient.connect(this.connectionUrl, function (err, db) {
|
MongoClient.connect(this.connectionUrl, function (err, client) {
|
||||||
if (err) {
|
if (err) {
|
||||||
winston.error('error connecting to mongodb', { error: err });
|
winston.error('error connecting to mongodb', { error: err });
|
||||||
callback(err);
|
callback(err);
|
||||||
} else {
|
} else {
|
||||||
callback(undefined, db);
|
callback(undefined, client.db(this.connectionDBName));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
Loading…
Reference in a new issue