From 5d49b3bf4f6f2f6f6886e328ef81915ae245dfc8 Mon Sep 17 00:00:00 2001 From: Arturs Sosins Date: Wed, 23 May 2018 22:33:48 +0300 Subject: [PATCH 1/6] Fix for MongoDB driver 3.0 breaking changes --- lib/utils.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 9292863..a3dbd17 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -129,9 +129,17 @@ exports.makeSkinClass = function makeSkinClass(NativeClass, useNativeConstructor self._state = STATE_CLOSE; } else { self._state = STATE_OPEN; - self._native = p_native; + if(skinClassName === "SkinDb"){ + self._native = p_native.db(); + self._native.logout = p_native.logout; + self._native.db = p_native.db; + self._native.close = p_native.close; + self._native.open = p_native.connect; + } + else + self._native = p_native; } - self._emitter.emit('open', err, p_native); + self._emitter.emit('open', err, self._native); }); } return this; From f84cb3c48670cf208bfcb532a1fae93cd9a44bd7 Mon Sep 17 00:00:00 2001 From: Arturs Sosins Date: Thu, 24 May 2018 08:56:01 +0300 Subject: [PATCH 2/6] Backwards compatibility check for older drivers --- lib/utils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index a3dbd17..a2abff7 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -129,7 +129,9 @@ exports.makeSkinClass = function makeSkinClass(NativeClass, useNativeConstructor self._state = STATE_CLOSE; } else { self._state = STATE_OPEN; - if(skinClassName === "SkinDb"){ + //check if it is MongoClient from new driver + if(skinClassName === "SkinDb" && typeof p_native.open === "undefined"){ + //change to db object and extend with missing methods self._native = p_native.db(); self._native.logout = p_native.logout; self._native.db = p_native.db; From ecea044af9a61f8d4743585878c7a373ea5ba3ab Mon Sep 17 00:00:00 2001 From: Arturs Sosins Date: Wed, 30 May 2018 08:58:35 +0300 Subject: [PATCH 3/6] [package] accept mongodb 3 as peer dependency too --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 537f75d..24bd102 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "node": ">= 0.4.0" }, "peerDependencies": { - "mongodb": "^2.0" + "mongodb": ">= 3.0" }, "devDependencies": { "istanbul": "0.3.17", From bde1bd7c4e0e789975aebc1fa66d1357102d8d45 Mon Sep 17 00:00:00 2001 From: Arturs Sosins Date: Fri, 25 Jan 2019 15:34:06 +0200 Subject: [PATCH 4/6] Store client reference --- lib/utils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/utils.js b/lib/utils.js index a2abff7..06d0056 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -133,6 +133,7 @@ exports.makeSkinClass = function makeSkinClass(NativeClass, useNativeConstructor if(skinClassName === "SkinDb" && typeof p_native.open === "undefined"){ //change to db object and extend with missing methods self._native = p_native.db(); + self._native._client = p_native; self._native.logout = p_native.logout; self._native.db = p_native.db; self._native.close = p_native.close; From fdd3cd44233df091331ab4c0680ab46df8811dc7 Mon Sep 17 00:00:00 2001 From: Arturs Sosins Date: Mon, 24 Feb 2020 21:01:46 +0200 Subject: [PATCH 5/6] New driver does not have methods attached to Cursor before it is connected --- lib/utils.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 06d0056..3eb8fa6 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -107,10 +107,65 @@ exports.makeSkinClass = function makeSkinClass(NativeClass, useNativeConstructor }); }); } - +if (NativeClass.name !== "Cursor") { for(var propName in NativeClass.prototype) { if(propName[0] != '_') bindSkin(propName); } +} +else { + var cursorMethods = [ + "setCursorBatchSize", + "cursorBatchSize", + "setCursorLimit", + "cursorLimit", + "setCursorSkip", + "cursorSkip", + "clone", + "isDead", + "isKilled", + "isNotified", + "bufferedCount", + "readBufferedDocuments", + "kill", + "rewind", + "next", + "hasNext", + "filter", + "hint", + "min", + "max", + "returnKey", + "showRecordId", + "setCursorOption", + "addCursorFlag", + "addQueryModifier", + "comment", + "maxAwaitTimeMS", + "maxTimeMS", + "maxTimeMs", + "project", + "sort", + "batchSize", + "collation", + "limit", + "skip", + "forEach", + "setReadPreference", + "toArray", + "count", + "close", + "map", + "isClosed", + "destroy", + "stream", + "transformStream", + "explain", + "getLogger", + ]; + for (var i = 0; i < cursorMethods.length; i++) { + SkinClass._bindMethod(cursorMethods[i]); + } +} SkinClass.prototype.open = function(callback) { switch (this._state) { From 50b75a87a48dbf9868eeee1431fa77ea594f5bdf Mon Sep 17 00:00:00 2001 From: Arturs Sosins Date: Wed, 26 Feb 2020 12:30:53 +0200 Subject: [PATCH 6/6] Bind methods correctly --- lib/utils.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 3eb8fa6..cb5af62 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -189,10 +189,10 @@ else { //change to db object and extend with missing methods self._native = p_native.db(); self._native._client = p_native; - self._native.logout = p_native.logout; - self._native.db = p_native.db; - self._native.close = p_native.close; - self._native.open = p_native.connect; + self._native.db = p_native.db.bind(p_native); + self._native.logout = p_native.logout.bind(p_native); + self._native.close = p_native.close.bind(p_native); + self._native.open = p_native.connect.bind(p_native); } else self._native = p_native;