aboutsummaryrefslogtreecommitdiff
path: root/node_modules/mongodb-core/lib/wireprotocol/shared.js
diff options
context:
space:
mode:
authornanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-18 10:54:08 +0000
committernanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-18 10:54:08 +0000
commita35da9f9ccc1124d9b6f4461c7216ffbb0285e2f (patch)
treed5b4b8548caae36a20e1258a8341dab4b3d522d2 /node_modules/mongodb-core/lib/wireprotocol/shared.js
parent16bbc66ebafc6f1a55e47dbda3f3c0f658fe715c (diff)
parentc1ce89359a7b54ec97b54ce577e5534c180c5c4b (diff)
merged
Diffstat (limited to 'node_modules/mongodb-core/lib/wireprotocol/shared.js')
-rw-r--r--node_modules/mongodb-core/lib/wireprotocol/shared.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/node_modules/mongodb-core/lib/wireprotocol/shared.js b/node_modules/mongodb-core/lib/wireprotocol/shared.js
new file mode 100644
index 0000000..3a20f51
--- /dev/null
+++ b/node_modules/mongodb-core/lib/wireprotocol/shared.js
@@ -0,0 +1,26 @@
+"use strict"
+
+var ReadPreference = require('../topologies/read_preference');
+
+var getReadPreference = function(cmd, options) {
+ // Default to command version of the readPreference
+ var readPreference = cmd.readPreference || new ReadPreference('primary');
+ // If we have an option readPreference override the command one
+ if(options.readPreference) {
+ readPreference = options.readPreference;
+ }
+
+ if(typeof readPreference == 'string') {
+ readPreference = new ReadPreference(readPreference);
+ }
+
+ if(!(readPreference instanceof ReadPreference)) {
+ throw new MongoError('readPreference must be a ReadPreference instance');
+ }
+
+ return readPreference;
+}
+
+module.exports = {
+ getReadPreference: getReadPreference
+}