Read preference option per query (#3865)
This commit is contained in:
committed by
Natan Rolnik
parent
422723fa31
commit
b6298feaa7
@@ -13,13 +13,13 @@ 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, maxTimeMS } = {}) {
|
||||
find(query, { skip, limit, sort, keys, maxTimeMS, readPreference } = {}) {
|
||||
// Support for Full Text Search - $text
|
||||
if(keys && keys.$score) {
|
||||
delete keys.$score;
|
||||
keys.score = {$meta: 'textScore'};
|
||||
}
|
||||
return this._rawFind(query, { skip, limit, sort, keys, maxTimeMS })
|
||||
return this._rawFind(query, { skip, limit, sort, keys, maxTimeMS, readPreference })
|
||||
.catch(error => {
|
||||
// Check for "no geoindex" error
|
||||
if (error.code != 17007 && !error.message.match(/unable to find index for .geoNear/)) {
|
||||
@@ -35,13 +35,13 @@ export default class MongoCollection {
|
||||
index[key] = '2d';
|
||||
return this._mongoCollection.createIndex(index)
|
||||
// Retry, but just once.
|
||||
.then(() => this._rawFind(query, { skip, limit, sort, keys, maxTimeMS }));
|
||||
.then(() => this._rawFind(query, { skip, limit, sort, keys, maxTimeMS, readPreference }));
|
||||
});
|
||||
}
|
||||
|
||||
_rawFind(query, { skip, limit, sort, keys, maxTimeMS } = {}) {
|
||||
_rawFind(query, { skip, limit, sort, keys, maxTimeMS, readPreference } = {}) {
|
||||
let findOperation = this._mongoCollection
|
||||
.find(query, { skip, limit, sort })
|
||||
.find(query, { skip, limit, sort, readPreference })
|
||||
|
||||
if (keys) {
|
||||
findOperation = findOperation.project(keys);
|
||||
@@ -54,8 +54,8 @@ export default class MongoCollection {
|
||||
return findOperation.toArray();
|
||||
}
|
||||
|
||||
count(query, { skip, limit, sort, maxTimeMS } = {}) {
|
||||
const countOperation = this._mongoCollection.count(query, { skip, limit, sort, maxTimeMS });
|
||||
count(query, { skip, limit, sort, maxTimeMS, readPreference } = {}) {
|
||||
const countOperation = this._mongoCollection.count(query, { skip, limit, sort, maxTimeMS, readPreference });
|
||||
|
||||
return countOperation;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user