Skip to content

Commit 4082297

Browse files
committed
[db] compatability fixes
1 parent 2be9ea1 commit 4082297

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

plugins/pluginManager.js

+39
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,17 @@ var pluginManager = function pluginManager() {
14401440
return;
14411441
}
14421442
return function(err, res) {
1443+
if (res) {
1444+
if (!res.result) {
1445+
res.result = {};
1446+
}
1447+
if (!res.result.ok) {
1448+
res.result.ok = !err;
1449+
}
1450+
if (!res.result.nModified) {
1451+
res.result.nModified = res.modifiedCount || 0;
1452+
}
1453+
}
14431454
if (err) {
14441455
if (retry && err.code === 11000) {
14451456
if (typeof retry === "function") {
@@ -1740,10 +1751,17 @@ var pluginManager = function pluginManager() {
17401751
logDbRead.d("aggregate " + collection + " %j %j" + at, query, options);
17411752
logDbRead.d("From connection %j", countlyDb._cly_debug);
17421753
var cursor = this._aggregate(query, options);
1754+
cursor._count = cursor.count;
1755+
cursor.count = function() {
1756+
return ob.countDocuments.apply(ob, arguments);
1757+
};
17431758
cursor._toArray = cursor.toArray;
17441759
cursor.toArray = function(cb) {
17451760
return handlePromiseErrors(cursor._toArray(logForReads(cb, e, copyArguments(args, "aggregate"))), e, copyArguments(arguments, "aggregate"));
17461761
};
1762+
cursor.isClosed = function() {
1763+
return cursor.closed || cursor.killed;
1764+
};
17471765
if (typeof callback === "function") {
17481766
return cursor.toArray(callback);
17491767
}
@@ -1782,10 +1800,17 @@ var pluginManager = function pluginManager() {
17821800
logDbRead.d("find " + collection + " %j %j" + at, query, options);
17831801
logDbRead.d("From connection %j", countlyDb._cly_debug);
17841802
var cursor = this._find(query, options);
1803+
cursor._count = cursor.count;
1804+
cursor.count = function() {
1805+
return ob.countDocuments.apply(ob, arguments);
1806+
};
17851807
cursor._toArray = cursor.toArray;
17861808
cursor.toArray = function(callback) {
17871809
return handlePromiseErrors(cursor._toArray(logForReads(callback, e, copyArguments(args, "find"))), e, copyArguments(arguments, "find"));
17881810
};
1811+
cursor.isClosed = function() {
1812+
return cursor.closed || cursor.killed;
1813+
};
17891814
return cursor;
17901815
};
17911816

@@ -1841,6 +1866,20 @@ var pluginManager = function pluginManager() {
18411866
return ob.findOneAndDelete(query, options, callback);
18421867
};
18431868

1869+
ob._drop = ob.drop;
1870+
ob.drop = function() {
1871+
if (!arguments.length) {
1872+
return ob._drop().catch(function(ex) {
1873+
if (ex.code !== 26) {
1874+
throw ex;
1875+
}
1876+
});
1877+
}
1878+
else {
1879+
return ob._drop.apply(ob, arguments);
1880+
}
1881+
};
1882+
18441883

18451884
countlyDb._collection_cache[collection] = ob;
18461885

0 commit comments

Comments
 (0)