mongoose 8.24.8 → 8.24.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,7 +6,7 @@ const MongooseError = require('../error/index');
|
|
|
6
6
|
function processConnectionOptions(uri, options) {
|
|
7
7
|
const opts = options ? options : {};
|
|
8
8
|
const readPreference = opts.readPreference
|
|
9
|
-
? opts.readPreference
|
|
9
|
+
? getReadPreferenceMode(opts.readPreference)
|
|
10
10
|
: getUriReadPreference(uri);
|
|
11
11
|
|
|
12
12
|
const clonedOpts = clone(opts);
|
|
@@ -40,6 +40,11 @@ function setsSecondaryRead(prefString) {
|
|
|
40
40
|
return !!(prefString === 'secondary' || prefString === 'secondaryPreferred');
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
function getReadPreferenceMode(readPreference) {
|
|
44
|
+
// the MongoDB driver also accepts a `ReadPreference` instance or a `{ mode }` object
|
|
45
|
+
return typeof readPreference === 'string' ? readPreference : readPreference.mode;
|
|
46
|
+
}
|
|
47
|
+
|
|
43
48
|
function getUriReadPreference(connectionString) {
|
|
44
49
|
const exp = /(?:&|\?)readPreference=(\w+)(?:&|$)/;
|
|
45
50
|
const match = exp.exec(connectionString);
|