The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/server/database/readSecondaryPreferred.ts

20 lines
936 B

import { ReadPreference, Db, ReadPreferenceOrMode } from 'mongodb';
export function readSecondaryPreferred(db: Db, tags: any[] = []): ReadPreferenceOrMode {
const { readPreferenceTags, readPreference } = db.options;
if (tags.length) {
return new ReadPreference(ReadPreference.SECONDARY_PREFERRED, tags);
}
if (Array.isArray(readPreferenceTags) && readPreferenceTags.length) {
return new ReadPreference(ReadPreference.SECONDARY_PREFERRED, readPreferenceTags);
}
if (readPreference instanceof ReadPreference && readPreference.tags.length) {
return new ReadPreference(ReadPreference.SECONDARY_PREFERRED, readPreference.tags);
}
// For some reason the new ReadPreference definition requires the tags parameter even not been
// required by the code implementation and, for some reason, when passing an empty array it
// doesn't ignore the tags and stop using the secondaries.
return ReadPreference.SECONDARY_PREFERRED;
}