Skip to content

Commit

Permalink
feat: update to mongodb 4.x driver
Browse files Browse the repository at this point in the history
  • Loading branch information
oplik0 authored Oct 19, 2021
1 parent c9794f0 commit 10d1bb9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
11 changes: 9 additions & 2 deletions lib/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ Channel.prototype.publish = function (event, message, callback) {
this.ready(function (collection) {
collection.insertOne({ event: event, message: message }, options, function (err, docs) {
if (err) return callback(err);
callback(null, docs.ops[0]);
collection.findOne({_id: docs.insertedId}, function (err, doc) {
if (err) return callback(err);
callback(err, doc);
})
});
});

Expand Down Expand Up @@ -210,7 +213,11 @@ Channel.prototype.latest = function (latest, callback) {

collection.insertOne({ 'dummy': true }, { safe: true }, function (err, docs) {
if (err) return cb(err);
callback(err, docs.ops[0], collection);
collection.findOne({_id: docs.insertedId}, function (err, doc) {
if (err) return cb(err);
callback(err, doc, collection);
})

});
});
}
Expand Down
7 changes: 3 additions & 4 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function Connection(uri, options) {
var self = this;

options || (options = {});
options.autoReconnect != null || (options.autoReconnect = true);

// It's a Db instance.
if (uri.collection) {
Expand All @@ -25,7 +24,7 @@ function Connection(uri, options) {
self.client = client;
self.db = client.db();
self.emit('connect', self.db);
self.db.on('error', function (err) {
self.client.on('error', function (err) {
self.emit('error', err);
});
});
Expand Down Expand Up @@ -54,8 +53,8 @@ Object.defineProperty(Connection.prototype, 'state', {
if (this.destroyed) {
state = 'destroyed';
}
else if (this.db) {
state = this.db.serverConfig.isConnected()
else if (this.client) {
state = this.client.topology.isConnected()
? 'connected' : 'disconnected';
} else {
state = 'connecting';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"url": "git://github.com/NodeBB/mubsub.git"
},
"dependencies": {
"mongodb": "^3.6.0"
"mongodb": "^4.1.3"
},
"devDependencies": {
"mocha": "^2.2.5"
Expand Down

0 comments on commit 10d1bb9

Please sign in to comment.