diff --git a/lib/winston-mongodb.js b/lib/winston-mongodb.js index 730fadf..5a6a9e5 100644 --- a/lib/winston-mongodb.js +++ b/lib/winston-mongodb.js @@ -1,6 +1,6 @@ /** * @module winston-mongodb - * @fileoverview Transport for outputting to a MongoDB database + * @fileoverview Winston transport for logging into MongoDB * @license MIT * @author charlie@nodejitsu.com (Charlie Robbins) * @author 0@39.yt (Yurij Mikhalevich) @@ -83,7 +83,15 @@ var MongoDB = exports.MongoDB = function(options) { function setupDatabaseAndEmptyQueue(db) { authorizeDb(db, function(err, db) { + if (err) { + console.error('winston-mongodb, initialization error: ', err); + return; + } createCollection(db, function(err, db) { + if (err) { + console.error('winston-mongodb, initialization error: ', err); + return; + } self.logDb = db; processOpQueue(); }); @@ -102,8 +110,14 @@ var MongoDB = exports.MongoDB = function(options) { if (self.capped) { opts = {capped: true, size: self.cappedSize}; } - db.createCollection(self.collection, opts, function() { - cb(null, db); + db.createCollection(self.collection, opts, function(err, col) { + if (err) { + cb(err); + return; + } + col.createIndex({timestamp: -1}, function(err) { + cb(err, db); + }); }); } diff --git a/package.json b/package.json index 45989b2..46b9e58 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "winston-mongodb", "license": "MIT", - "version": "1.1.2", + "version": "1.2.0", "description": "A MongoDB transport for winston", "author": "Charlie Robbins ", "contributors": [