Skip to content

Commit

Permalink
fix: removed depreciation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
boycce committed Apr 14, 2022
1 parent 118d8c4 commit 6db73bb
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
let util = require('./util')
var MongoClient = require('mongodb').MongoClient
let monk = require('monk')
let debug = require('debug')

Expand Down Expand Up @@ -87,3 +88,42 @@ let models = function(path) {
})
return models
}

monk.manager.prototype.open = function (uri, opts, fn) {
/*
* Monkey patch to remove db event listener warnings
* @todo remove when monk is removed
* @see https://www.mongodb.com/community/forums/t/node-44612-deprecationwarning-listening-to-events-on-
the-db-class-has-been-deprecated-and-will-be-removed-in-the-next-major-version/15849/4
*/
var STATE = {
CLOSED: 'closed',
OPENING: 'opening',
OPEN: 'open'
}
MongoClient.connect(uri, opts, function (err, client) {
// this = Manager
if (err) {
this._state = STATE.CLOSED
this.emit('error-opening', err)
} else {
this._state = STATE.OPEN

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

// set up events
var self = this
;['authenticated', 'close', 'error', 'parseError', 'timeout'].forEach(function (eventName) {
self._client.on(eventName, function (e) {
self.emit(eventName, e)
})
})

this.emit('open', this._db)
}
if (fn) {
fn(err, this)
}
}.bind(this))
}

0 comments on commit 6db73bb

Please sign in to comment.