Skip to content

Node.js based forum software built for the modern web

cleanup mongo init

Baris Usakli400845ce6c38
diff --git a/src/database/mongo.js b/src/database/mongo.js
index 211040ad2d..e9cfaa68e5 100644
--- a/src/database/mongo.js
+++ b/src/database/mongo.js
@@ -13,13 +13,13 @@
module.init = function(callback) {
mongoClient.connect('mongodb://'+ mongoHost + ':' + nconf.get('mongo:port') + '/' + nconf.get('mongo:database'), function(err, _db) {
- db = _db;
-
if(err) {
winston.error("NodeBB could not connect to your Mongo database. Mongo returned the following error: " + err.message);
process.exit();
}
+ db = _db;
+
module.client = db;
module.sessionStore = new mongoStore({
@@ -27,46 +27,49 @@
});
- // TODO : what is the db user name??
if(nconf.get('mongo:password') && nconf.get('mongo:username')) {
db.authenticate(nconf.get('mongo:username'), nconf.get('mongo:password'), function (err) {
if(err) {
winston.error(err.message);
+ process.exit();
}
- process.exit();
+ createCollections();
});
+ } else {
+ createCollections();
}
+ function createCollections() {
+ db.createCollection('objects', function(err, collection) {
+ if(err) {
+ winston.error("Error creating collection " + err.message);
+ return;
+ }
+ if(collection) {
+ collection.ensureIndex({_key :1, setName:1}, {background:true}, function(err, name){
+ if(err) {
+ winston.error("Error creating index " + err.message);
+ }
+ });
+ }
+ });
- db.createCollection('objects', function(err, collection) {
- if(err) {
- winston.error("Error creating collection " + err.message);
- return;
- }
- if(collection) {
- collection.ensureIndex({_key :1, setName:1}, {background:true}, function(err, name){
- if(err) {
- winston.error("Error creating index " + err.message);
- }
- });
- }
- });
-
- db.createCollection('search', function(err, collection) {
- if(err) {
- winston.error("Error creating collection " + err.message);
- return;
- }
- if(collection) {
- collection.ensureIndex({content:'text'}, {background:true}, function(err, name){
- if(err) {
- winston.error("Error creating index " + err.message);
- }
- });
- }
- });
+ db.createCollection('search', function(err, collection) {
+ if(err) {
+ winston.error("Error creating collection " + err.message);
+ return;
+ }
+ if(collection) {
+ collection.ensureIndex({content:'text'}, {background:true}, function(err, name){
+ if(err) {
+ winston.error("Error creating index " + err.message);
+ }
+ });
+ }
+ });
- callback(err);
+ callback(null);
+ }
});
}
diff --git a/src/upgrade.js b/src/upgrade.js
index 99657007f7..75265c4643 100644
--- a/src/upgrade.js
+++ b/src/upgrade.js
@@ -309,7 +309,6 @@ Upgrade.upgradeMongo = function(callback) {
async.series([
function(next) {
db.get('schemaDate', function(err, value) {
- console.log(schemaDate)
schemaDate = value;
thisSchemaDate = new Date(2013, 11, 6).getTime();
next();