diff --git a/lib/utils.js b/lib/utils.js index 9292863..cb5af62 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) { @@ -129,9 +184,20 @@ exports.makeSkinClass = function makeSkinClass(NativeClass, useNativeConstructor self._state = STATE_CLOSE; } else { self._state = STATE_OPEN; - self._native = p_native; + //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._client = p_native; + 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; } - self._emitter.emit('open', err, p_native); + self._emitter.emit('open', err, self._native); }); } return this; 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",