connect-mongodb
connect-mongodb copied to clipboard
TypeError: Cannot call method 'remove' of null when trying init connection
You should apply this changes in lib/connect-mongodb.js file
new
... @@ -44,6 +44,16 @@ var MONGOSTORE = module.exports = function MongoStore(options, callback) {
44 } else {
45 getCollection(db, callback);
46 }
47 +
48 + if (options.reapInterval !== -1) {
49 + var reap_interval = setInterval(function () {
50 + _collection.remove({expires: {'$lte': Date.now()}}, function () { });
51 + }, options.reapInterval || _defaults.reapInterval, this); // _defaults to each minute
52 +
53 + db.on('close', function () {
54 + clearInterval(reap_interval);
55 + });
56 + }
57 }
58
59 if (options.url) {
... @@ -77,16 +87,6 @@ var MONGOSTORE = module.exports = function MongoStore(options, callback) {
87
88 Store.call(this, options);
89
- if (options.reapInterval !== -1) {
- var reap_interval = setInterval(function () {
- _collection.remove({expires: {'$lte': Date.now()}}, function () { });
- }, options.reapInterval || _defaults.reapInterval, this); // _defaults to each minute
-
- db.on('close', function () {
- clearInterval(reap_interval);
- });
- }
-
90 if (server_config.isConnected()) {
91 authenticateAndGetCollection(callback);