From 13e9200ed2a173de858f313c4681369f53038ab8 Mon Sep 17 00:00:00 2001 From: Manuel Barkau Date: Wed, 12 Jan 2022 14:31:17 +0100 Subject: [PATCH] update mongoDB driver to support 3.6.3 .authenticate is unsupported since 3.6.x relase of mongoDB. --- lib/adapters/mongodb.js | 56 +++++++++++------------------------------ package.json | 6 ++++- 2 files changed, 20 insertions(+), 42 deletions(-) diff --git a/lib/adapters/mongodb.js b/lib/adapters/mongodb.js index d0bc0f6..c148a6d 100644 --- a/lib/adapters/mongodb.js +++ b/lib/adapters/mongodb.js @@ -48,7 +48,9 @@ exports.initialize = function initializeSchema(schema, callback) { s.host = s.host || 'localhost'; s.port = parseInt(s.port || '27017', 10); s.database = s.database || process.env.USER || 'test'; - if (!s.url) { + if (!s.url && s.username && s.password) { + s.url = 'mongodb://' + s.username + ':' + s.password + '@' + s.host + ':' + s.port + '/' + s.database; + } else if (!s.url) { s.url = 'mongodb://' + s.host + ':' + s.port + '/' + s.database; } } @@ -72,56 +74,28 @@ function MongoDB(s, schema, callback) { self.db = client.db(s.database); self.client = client; self.schema = schema; - self.connection() - .then(callback) - .catch(callback); + self.schema.client = self.client; + callback(); }.bind(this)); } -MongoDB.prototype.connection = function () { - var t = this; - return new Promise(function (resolve, reject) { - if (t.s.username && t.s.password) { - t.client.authenticate(t.s.username, t.s.password, function (err, result) { - if (err) { - reject(err); - } else { - t.schema.client = t.client; - resolve(); - } - }); - } else { - t.schema.client = t.client; - resolve(); - } - }); -}; - MongoDB.prototype.define = function (descr) { var self = this; if (!descr.settings) { descr.settings = {}; } self._models[descr.model.modelName] = descr; - self.connection().then(function (db) { - Object.keys(descr.properties).forEach(function (k) { - if (typeof descr.properties[k].index !== 'undefined' || typeof descr.properties[k].unique !== 'undefined') { - var fields = {}, params = {}; - fields[k] = 1; - params['name'] = '_' + k + '_'; - if (typeof descr.properties[k].unique !== 'undefined') { - params['unique'] = true; - } - if (db) { - self.db = db; - } - self.ensureIndex(descr.model.modelName, fields, params); + Object.keys(descr.properties).forEach(function (k) { + if (typeof descr.properties[k].index !== 'undefined' || typeof descr.properties[k].unique !== 'undefined') { + var fields = {}, params = {}; + fields[k] = 1; + params['name'] = '_' + k + '_'; + if (typeof descr.properties[k].unique !== 'undefined') { + params['unique'] = true; } - }); - }) - .catch(function (err) { - console.log('define err:', self.db, err); - }); + self.ensureIndex(descr.model.modelName, fields, params); + } + }); }; MongoDB.prototype.defineProperty = function (model, prop, params) { diff --git a/package.json b/package.json index 8956183..fba1438 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,10 @@ { "name": "Tyrone Dougherty", "email": "email@tyronedougherty.com" + }, + { + "name": "Manuel Barkau", + "email": "manuelbarkau1@freenet.de" } ], "keywords": [ @@ -124,7 +128,7 @@ "jshint": "2.x", "mocha": "^5.1.1", "moment": "^2.22.1", - "mongodb": "^3.0.7", + "mongodb": "^3.6.3", "mongoose": "^5.0.17", "mysql": "^2.15.0", "node-neo4j": "^2.0.3",