From 08f94f85523c942e43ec5f74c7aaa896a01d6b53 Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Sun, 27 Nov 2011 09:17:21 -0800 Subject: [PATCH] catch mongodb-native errors --- lib/app.js | 4 ++-- lib/db.js | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/app.js b/lib/app.js index 97850ae..aac5ddf 100644 --- a/lib/app.js +++ b/lib/app.js @@ -1,7 +1,7 @@ var express = require('express') , app = express.createServer() , db = require('./db').db - , mongoStore = require('connect-mongodb'); + , MongoStore = require('connect-mongodb'); ; // expose the app as a module so everyone can use it @@ -34,7 +34,7 @@ app.configure(function(){ secret: 'secret', key: 'deployd.sid', cookie: {httpOnly: false}, - store: new mongoStore({db: db}) + store: new MongoStore({db: db}) })); app.use(app.router); app.use(express.static(__dirname + '/../public')); diff --git a/lib/db.js b/lib/db.js index eec7f5d..4bba1ce 100644 --- a/lib/db.js +++ b/lib/db.js @@ -90,8 +90,11 @@ module.exports = { collection(db, model, function(err, collection) { var index = {}; index[property] = 1; - - collection.ensureIndex(index, options, fn); + try { + collection.ensureIndex(index, options, fn); + } catch(e) { + console.error('MongoError:', e); + } }); })