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.

45 lines
758 B

  1. /*!
  2. * Module dependencies.
  3. */
  4. var mongodb = require('mongodb');
  5. var ReadPref = mongodb.ReadPreference;
  6. /*!
  7. * Converts arguments to ReadPrefs the driver
  8. * can understand.
  9. *
  10. * @param {String|Array} pref
  11. * @param {Array} [tags]
  12. */
  13. module.exports = function readPref(pref, tags) {
  14. if (Array.isArray(pref)) {
  15. tags = pref[1];
  16. pref = pref[0];
  17. }
  18. if (pref instanceof ReadPref) {
  19. return pref;
  20. }
  21. switch (pref) {
  22. case 'p':
  23. pref = 'primary';
  24. break;
  25. case 'pp':
  26. pref = 'primaryPreferred';
  27. break;
  28. case 's':
  29. pref = 'secondary';
  30. break;
  31. case 'sp':
  32. pref = 'secondaryPreferred';
  33. break;
  34. case 'n':
  35. pref = 'nearest';
  36. break;
  37. }
  38. return new ReadPref(pref, tags);
  39. };