fix pubsub when only mongodb is used

v1.18.x
Barış Soner Uşaklı 7 years ago
parent 6d155ded11
commit 8263f81d0c

@ -62,7 +62,7 @@ mongoModule.questions = [
mongoModule.helpers = mongoModule.helpers || {};
mongoModule.helpers.mongo = require('./mongo/helpers');
function getConnectionString() {
mongoModule.getConnectionString = function () {
var usernamePassword = '';
if (nconf.get('mongo:username') && nconf.get('mongo:password')) {
usernamePassword = nconf.get('mongo:username') + ':' + encodeURIComponent(nconf.get('mongo:password')) + '@';
@ -90,15 +90,9 @@ function getConnectionString() {
}
return nconf.get('mongo:uri') || 'mongodb://' + usernamePassword + servers.join() + '/' + nconf.get('mongo:database');
}
mongoModule.init = function (callback) {
callback = callback || function () { };
var mongoClient = require('mongodb').MongoClient;
var connString = getConnectionString();
};
mongoModule.getConnectionOptions = function () {
var connOptions = {
poolSize: 10,
reconnectTries: 3600,
@ -106,7 +100,16 @@ mongoModule.init = function (callback) {
autoReconnect: true,
};
connOptions = _.merge(connOptions, nconf.get('mongo:options') || {});
return _.merge(connOptions, nconf.get('mongo:options') || {});
};
mongoModule.init = function (callback) {
callback = callback || function () { };
var mongoClient = require('mongodb').MongoClient;
var connString = mongoModule.getConnectionString();
var connOptions = mongoModule.getConnectionOptions();
mongoClient.connect(connString, connOptions, function (err, _client) {
if (err) {
@ -272,5 +275,5 @@ mongoModule.close = function (callback) {
mongoModule.socketAdapter = function () {
var mongoAdapter = require('socket.io-adapter-mongo');
return mongoAdapter(getConnectionString());
return mongoAdapter(mongoModule.getConnectionString());
};

@ -1,8 +1,8 @@
'use strict';
var mubsub = require('mubsub');
var mubsub = require('mubsub-nbb');
var db = require('../mongo');
var client = mubsub(db.client);
var client = mubsub(db.getConnectionString(), db.getConnectionOptions());
module.exports = client.channel('pubsub');

Loading…
Cancel
Save