Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 69 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"node": ">= 0.4.0"
},
"peerDependencies": {
"mongodb": "^2.0"
"mongodb": ">= 3.0"
},
"devDependencies": {
"istanbul": "0.3.17",
Expand Down