mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 12:36:02 +01:00
closes #5271
This commit is contained in:
@@ -111,13 +111,11 @@
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
createSessionStore();
|
||||
createIndices();
|
||||
createSessionStore();
|
||||
});
|
||||
} else {
|
||||
winston.warn('You have no mongo password setup!');
|
||||
createSessionStore();
|
||||
createIndices();
|
||||
}
|
||||
|
||||
function createSessionStore() {
|
||||
@@ -137,32 +135,39 @@
|
||||
db: db
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function createIndices() {
|
||||
winston.info('[database] Checking database indices.');
|
||||
async.series([
|
||||
async.apply(createIndex, 'objects', {_key: 1, score: -1}, {background: true}),
|
||||
async.apply(createIndex, 'objects', {_key: 1, value: -1}, {background: true, unique: true, sparse: true}),
|
||||
async.apply(createIndex, 'objects', {expireAt: 1}, {expireAfterSeconds: 0, background: true})
|
||||
], function (err) {
|
||||
if (err) {
|
||||
winston.error('Error creating index ' + err.message);
|
||||
}
|
||||
winston.info('[database] Checking database indices done!');
|
||||
callback(err);
|
||||
});
|
||||
}
|
||||
|
||||
function createIndex(collection, index, options, callback) {
|
||||
db.collection(collection).createIndex(index, options, callback);
|
||||
}
|
||||
callback();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.createIndices = function(callback) {
|
||||
function createIndex(collection, index, options, callback) {
|
||||
module.client.collection(collection).createIndex(index, options, callback);
|
||||
}
|
||||
|
||||
if (!module.client) {
|
||||
winston.warn('[database/createIndices] database not initialized');
|
||||
return callback();
|
||||
}
|
||||
|
||||
winston.info('[database] Checking database indices.');
|
||||
async.series([
|
||||
async.apply(createIndex, 'objects', {_key: 1, score: -1}, {background: true}),
|
||||
async.apply(createIndex, 'objects', {_key: 1, value: -1}, {background: true, unique: true, sparse: true}),
|
||||
async.apply(createIndex, 'objects', {expireAt: 1}, {expireAfterSeconds: 0, background: true})
|
||||
], function (err) {
|
||||
if (err) {
|
||||
winston.error('Error creating index ' + err.message);
|
||||
return callback(err);
|
||||
}
|
||||
winston.info('[database] Checking database indices done!');
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
module.checkCompatibility = function (callback) {
|
||||
var mongoPkg = require.main.require('./node_modules/mongodb/package.json'),
|
||||
err = semver.lt(mongoPkg.version, '2.0.0') ? new Error('The `mongodb` package is out-of-date, please run `./nodebb setup` again.') : null;
|
||||
var mongoPkg = require.main.require('./node_modules/mongodb/package.json');
|
||||
var err = semver.lt(mongoPkg.version, '2.0.0') ? new Error('The `mongodb` package is out-of-date, please run `./nodebb setup` again.') : null;
|
||||
|
||||
if (err) {
|
||||
err.stacktrace = false;
|
||||
|
||||
Reference in New Issue
Block a user