Skip to content

Commit

Permalink
update mongodb to 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
mpangrazzi committed May 2, 2019
1 parent 39228ea commit c52f595
Show file tree
Hide file tree
Showing 5 changed files with 13,222 additions and 54 deletions.
6 changes: 3 additions & 3 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ Collection.prototype.findOne = function (query, opts, fn) {

return this._dispatch(function findOne (args) {
return args.col.find(args.query, args.options).limit(1).toArray()
.then(function (docs) {
return (docs && docs[0]) || null
})
.then(function (docs) {
return (docs && docs[0]) || null
})
})({options: opts, query: query, callback: fn}, 'findOne')
}

Expand Down
20 changes: 11 additions & 9 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ inherits(Manager, EventEmitter)
* @private
*/
Manager.prototype.open = function (uri, opts, fn) {
MongoClient.connect(uri, opts, function (err, db) {
if (err || !db) {
MongoClient.connect(uri, opts, function (err, client) {
if (err) {
this._state = STATE.CLOSED
this.emit('error-opening', err)
} else {
this._state = STATE.OPEN
this._db = db

this._client = client
this._db = client.db()

// set up events
var self = this
Expand All @@ -142,7 +144,7 @@ Manager.prototype.open = function (uri, opts, fn) {
})
})

this.emit('open', db)
this.emit('open', this._db)
}
if (fn) {
fn(err, this)
Expand Down Expand Up @@ -212,8 +214,8 @@ Manager.prototype.close = function (force, fn) {
}

var self = this
function close (resolve, db) {
db.close(force, function () {
function close (resolve) {
self._client.close(force, function () {
self._state = STATE.CLOSED
if (fn) {
fn()
Expand All @@ -230,14 +232,14 @@ Manager.prototype.close = function (force, fn) {
return Promise.resolve()
case STATE.OPENING:
return new Promise(function (resolve) {
self._queue.push(function (db) {
close(resolve, db)
self._queue.push(function () {
close(resolve)
})
})
case STATE.OPEN:
default:
return new Promise(function (resolve) {
close(resolve, self._db)
close(resolve)
})
}
}
Expand Down
Loading

0 comments on commit c52f595

Please sign in to comment.