Skip to content

Commit d316901

Browse files
committed
compatibility with new mongodb version (3.x)
1 parent d6fbc08 commit d316901

18 files changed

+44
-49
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ and you can use it in this way
596596

597597
# License
598598

599-
Copyright (c) 2017 Adriano Raiano, Jan Muehlemann
599+
Copyright (c) 2018 Adriano Raiano, Jan Muehlemann
600600

601601
Permission is hereby granted, free of charge, to any person obtaining a copy
602602
of this software and associated documentation files (the "Software"), to deal

index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
var Eventstore = require('./lib/eventstore'),
42
Base = require('./lib/base'),
53
_ = require('lodash'),

lib/base.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
var util = require('util'),
42
EventEmitter = require('events').EventEmitter,
53
prequire = require('parent-require'),

lib/databases/azuretable.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
'use strict';
2-
3-
41
var util = require('util'),
52
Store = require('../base'),
63
_ = require('lodash'),

lib/databases/dynamodb.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
var util = require('util'),
42
Store = require('../base'),
53
_ = require('lodash'),

lib/databases/elasticsearch.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
var util = require('util'),
42
Store = require('../base'),
53
_ = require('lodash'),

lib/databases/inmemory.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
var util = require('util'),
42
Store = require('../base'),
53
_ = require('lodash'),

lib/databases/mongodb.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
var util = require('util'),
42
Store = require('../base'),
53
_ = require('lodash'),
@@ -73,17 +71,38 @@ _.extend(Mongo.prototype, {
7371
connectionUrl = 'mongodb://' + authString + memberString + '/' + options.dbName + optionsString;
7472
}
7573

76-
var client = new mongo.MongoClient();
74+
var client;
7775

78-
client.connect(connectionUrl, options.options, function(err, db) {
79-
if (err) {
80-
debug(err);
81-
if (callback) callback(err);
82-
return;
83-
}
76+
if (mongo.MongoClient.length === 2) {
77+
client = new mongo.MongoClient(connectionUrl, options.options);
78+
client.connect(function(err, cl) {
79+
if (err) {
80+
debug(err);
81+
if (callback) callback(err);
82+
return;
83+
}
84+
85+
self.db = cl.db(cl.s.options.dbName);
86+
if (!self.db.close) {
87+
self.db.close = cl.close.bind(cl);
88+
}
89+
initDb();
90+
});
91+
} else {
92+
client = new mongo.MongoClient();
93+
client.connect(connectionUrl, options.options, function(err, db) {
94+
if (err) {
95+
debug(err);
96+
if (callback) callback(err);
97+
return;
98+
}
8499

85-
self.db = db;
100+
self.db = db;
101+
initDb();
102+
});
103+
}
86104

105+
function initDb() {
87106
self.db.on('close', function() {
88107
self.emit('disconnect');
89108
self.stopHeartbeat();
@@ -123,7 +142,7 @@ _.extend(Mongo.prototype, {
123142
}
124143

125144
finish();
126-
});
145+
}
127146
},
128147

129148
stopHeartbeat: function () {

lib/databases/redis.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
var util = require('util'),
42
fs = require('fs'),
53
Store = require('../base'),

lib/databases/tingodb.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
var util = require('util'),
42
Store = require('../base'),
53
_ = require('lodash'),

0 commit comments

Comments
 (0)