PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/node_modules/mongodb-core/lib/wireprotocol/shared.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 27 lines | 19 code | 6 blank | 2 comment | 5 complexity | 5733b9a6ec7ca34ced87a7b88802ae0f MD5 | raw file
 1"use strict"
 2
 3var ReadPreference = require('../topologies/read_preference'),
 4  MongoError = require('../error');
 5
 6var getReadPreference = function(cmd, options) {
 7  // Default to command version of the readPreference
 8  var readPreference = cmd.readPreference || new ReadPreference('primary');
 9  // If we have an option readPreference override the command one
10  if(options.readPreference) {
11    readPreference = options.readPreference;
12  }
13
14  if(typeof readPreference == 'string') {
15    readPreference = new ReadPreference(readPreference);
16  }
17
18  if(!(readPreference instanceof ReadPreference)) {
19    throw new MongoError('readPreference must be a ReadPreference instance');
20  }
21
22  return readPreference;
23}
24
25module.exports = {
26  getReadPreference: getReadPreference
27}