Add support for maxTimeMS mongoOption (#3018)
This commit is contained in:
@@ -13,8 +13,8 @@ export default class MongoCollection {
|
||||
// none, then build the geoindex.
|
||||
// This could be improved a lot but it's not clear if that's a good
|
||||
// idea. Or even if this behavior is a good idea.
|
||||
find(query, { skip, limit, sort, keys } = {}) {
|
||||
return this._rawFind(query, { skip, limit, sort, keys })
|
||||
find(query, { skip, limit, sort, keys, maxTimeMS } = {}) {
|
||||
return this._rawFind(query, { skip, limit, sort, keys, maxTimeMS })
|
||||
.catch(error => {
|
||||
// Check for "no geoindex" error
|
||||
if (error.code != 17007 && !error.message.match(/unable to find index for .geoNear/)) {
|
||||
@@ -30,22 +30,29 @@ export default class MongoCollection {
|
||||
index[key] = '2d';
|
||||
return this._mongoCollection.createIndex(index)
|
||||
// Retry, but just once.
|
||||
.then(() => this._rawFind(query, { skip, limit, sort, keys }));
|
||||
.then(() => this._rawFind(query, { skip, limit, sort, keys, maxTimeMS }));
|
||||
});
|
||||
}
|
||||
|
||||
_rawFind(query, { skip, limit, sort, keys } = {}) {
|
||||
_rawFind(query, { skip, limit, sort, keys, maxTimeMS } = {}) {
|
||||
let findOperation = this._mongoCollection
|
||||
.find(query, { skip, limit, sort })
|
||||
|
||||
if (keys) {
|
||||
findOperation = findOperation.project(keys);
|
||||
}
|
||||
|
||||
if (maxTimeMS) {
|
||||
findOperation = findOperation.maxTimeMS(maxTimeMS);
|
||||
}
|
||||
|
||||
return findOperation.toArray();
|
||||
}
|
||||
|
||||
count(query, { skip, limit, sort } = {}) {
|
||||
return this._mongoCollection.count(query, { skip, limit, sort });
|
||||
count(query, { skip, limit, sort, maxTimeMS } = {}) {
|
||||
let countOperation = this._mongoCollection.count(query, { skip, limit, sort, maxTimeMS });
|
||||
|
||||
return countOperation;
|
||||
}
|
||||
|
||||
insertOne(object) {
|
||||
|
||||
Reference in New Issue
Block a user