|
|
|
@ -1,18 +1,20 @@
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
(function (module) {
|
|
|
|
|
var winston = require('winston');
|
|
|
|
|
var async = require('async');
|
|
|
|
|
var nconf = require('nconf');
|
|
|
|
|
var session = require('express-session');
|
|
|
|
|
var _ = require('underscore');
|
|
|
|
|
var semver = require('semver');
|
|
|
|
|
var db;
|
|
|
|
|
|
|
|
|
|
_.mixin(require('underscore.deep'));
|
|
|
|
|
|
|
|
|
|
module.questions = [
|
|
|
|
|
|
|
|
|
|
var winston = require('winston');
|
|
|
|
|
var async = require('async');
|
|
|
|
|
var nconf = require('nconf');
|
|
|
|
|
var session = require('express-session');
|
|
|
|
|
var _ = require('underscore');
|
|
|
|
|
var semver = require('semver');
|
|
|
|
|
var db;
|
|
|
|
|
|
|
|
|
|
_.mixin(require('underscore.deep'));
|
|
|
|
|
|
|
|
|
|
var mongoModule = module.exports;
|
|
|
|
|
|
|
|
|
|
mongoModule.questions = [
|
|
|
|
|
{
|
|
|
|
|
name: 'mongo:host',
|
|
|
|
|
description: 'Host IP or address of your MongoDB instance',
|
|
|
|
@ -40,12 +42,12 @@
|
|
|
|
|
description: 'MongoDB database name',
|
|
|
|
|
default: nconf.get('mongo:database') || 'nodebb',
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
module.helpers = module.helpers || {};
|
|
|
|
|
module.helpers.mongo = require('./mongo/helpers');
|
|
|
|
|
mongoModule.helpers = mongoModule.helpers || {};
|
|
|
|
|
mongoModule.helpers.mongo = require('./mongo/helpers');
|
|
|
|
|
|
|
|
|
|
module.init = function (callback) {
|
|
|
|
|
mongoModule.init = function (callback) {
|
|
|
|
|
callback = callback || function () { };
|
|
|
|
|
|
|
|
|
|
var mongoClient = require('mongodb').MongoClient;
|
|
|
|
@ -93,13 +95,13 @@
|
|
|
|
|
|
|
|
|
|
db = _db;
|
|
|
|
|
|
|
|
|
|
module.client = db;
|
|
|
|
|
mongoModule.client = db;
|
|
|
|
|
|
|
|
|
|
require('./mongo/main')(db, module);
|
|
|
|
|
require('./mongo/hash')(db, module);
|
|
|
|
|
require('./mongo/sets')(db, module);
|
|
|
|
|
require('./mongo/sorted')(db, module);
|
|
|
|
|
require('./mongo/list')(db, module);
|
|
|
|
|
require('./mongo/main')(db, mongoModule);
|
|
|
|
|
require('./mongo/hash')(db, mongoModule);
|
|
|
|
|
require('./mongo/sets')(db, mongoModule);
|
|
|
|
|
require('./mongo/sorted')(db, mongoModule);
|
|
|
|
|
require('./mongo/list')(db, mongoModule);
|
|
|
|
|
|
|
|
|
|
if (nconf.get('mongo:password') && nconf.get('mongo:username')) {
|
|
|
|
|
db.authenticate(nconf.get('mongo:username'), nconf.get('mongo:password'), function (err) {
|
|
|
|
@ -110,9 +112,9 @@
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.initSessionStore = function (callback) {
|
|
|
|
|
mongoModule.initSessionStore = function (callback) {
|
|
|
|
|
var meta = require('../meta');
|
|
|
|
|
var sessionStore;
|
|
|
|
|
|
|
|
|
@ -123,27 +125,27 @@
|
|
|
|
|
var rdb = require('./redis');
|
|
|
|
|
rdb.client = rdb.connect();
|
|
|
|
|
|
|
|
|
|
module.sessionStore = new sessionStore({
|
|
|
|
|
mongoModule.sessionStore = new sessionStore({
|
|
|
|
|
client: rdb.client,
|
|
|
|
|
ttl: ttl,
|
|
|
|
|
});
|
|
|
|
|
} else if (nconf.get('mongo')) {
|
|
|
|
|
sessionStore = require('connect-mongo')(session);
|
|
|
|
|
module.sessionStore = new sessionStore({
|
|
|
|
|
mongoModule.sessionStore = new sessionStore({
|
|
|
|
|
db: db,
|
|
|
|
|
ttl: ttl,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.createIndices = function (callback) {
|
|
|
|
|
mongoModule.createIndices = function (callback) {
|
|
|
|
|
function createIndex(collection, index, options, callback) {
|
|
|
|
|
module.client.collection(collection).createIndex(index, options, callback);
|
|
|
|
|
mongoModule.client.collection(collection).createIndex(index, options, callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!module.client) {
|
|
|
|
|
if (!mongoModule.client) {
|
|
|
|
|
winston.warn('[database/createIndices] database not initialized');
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
@ -161,9 +163,9 @@
|
|
|
|
|
winston.info('[database] Checking database indices done!');
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.checkCompatibility = function (callback) {
|
|
|
|
|
mongoModule.checkCompatibility = function (callback) {
|
|
|
|
|
var mongoPkg = require('mongodb/package.json');
|
|
|
|
|
|
|
|
|
|
if (semver.lt(mongoPkg.version, '2.0.0')) {
|
|
|
|
@ -171,9 +173,9 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.info = function (db, callback) {
|
|
|
|
|
mongoModule.info = function (db, callback) {
|
|
|
|
|
if (!db) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
@ -231,9 +233,8 @@
|
|
|
|
|
|
|
|
|
|
callback(null, stats);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.close = function () {
|
|
|
|
|
mongoModule.close = function () {
|
|
|
|
|
db.close();
|
|
|
|
|
};
|
|
|
|
|
}(exports));
|
|
|
|
|
};
|
|
|
|
|