aboutsummaryrefslogtreecommitdiff
path: root/node_modules/mongodb/lib/read_preference.js
diff options
context:
space:
mode:
authornanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-08-14 10:13:55 +0000
committernanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-08-14 10:13:55 +0000
commita532390f81e35f611fd02ad3d543f4d52217ca3c (patch)
tree7bebb4f5614afb82c3103b6e9730a62f0b97a42d /node_modules/mongodb/lib/read_preference.js
parentef2674cfe13d2c425c5a3b312244c46f2531979d (diff)
Fixed signin and signup
Diffstat (limited to 'node_modules/mongodb/lib/read_preference.js')
-rw-r--r--node_modules/mongodb/lib/read_preference.js50
1 files changed, 39 insertions, 11 deletions
diff --git a/node_modules/mongodb/lib/read_preference.js b/node_modules/mongodb/lib/read_preference.js
index 73b253a..0c8da2b 100644
--- a/node_modules/mongodb/lib/read_preference.js
+++ b/node_modules/mongodb/lib/read_preference.js
@@ -3,7 +3,7 @@
/**
* @fileOverview The **ReadPreference** class is a class that represents a MongoDB ReadPreference and is
* used to construct connections.
- *
+ *
* @example
* var Db = require('mongodb').Db,
* ReplSet = require('mongodb').ReplSet,
@@ -27,7 +27,7 @@
/**
* Creates a new ReadPreference instance
- *
+ *
* Read Preferences
* - **ReadPreference.PRIMARY**, Read from primary only. All operations produce an error (throw an exception where applicable) if primary is unavailable. Cannot be combined with tags (This is the default.).
* - **ReadPreference.PRIMARY_PREFERRED**, Read from primary if available, otherwise a secondary.
@@ -37,17 +37,34 @@
*
* @class
* @param {string} mode The ReadPreference mode as listed above.
- * @param {object} tags An object representing read preference tags.
+ * @param {array} tags An object representing read preference tags.
+ * @param {object} [options] Additional read preference options
+ * @param {number} [options.maxStalenessMS] Max Secondary Read Stalleness in Miliseconds
* @property {string} mode The ReadPreference mode.
- * @property {object} tags The ReadPreference tags.
+ * @property {array} tags The ReadPreference tags.
+ * @property {object} options Additional read preference options
+ * @property {number} maxStalenessMS MaxStalenessMS value for the read preference
* @return {ReadPreference} a ReadPreference instance.
- */
-var ReadPreference = function(mode, tags) {
- if(!(this instanceof ReadPreference))
- return new ReadPreference(mode, tags);
+ */
+var ReadPreference = function(mode, tags, options) {
+ if(!(this instanceof ReadPreference)) {
+ return new ReadPreference(mode, tags, options);
+ }
+
this._type = 'ReadPreference';
this.mode = mode;
this.tags = tags;
+ this.options = options;
+
+ // If no tags were passed in
+ if(tags && typeof tags == 'object') {
+ this.options = tags, this.tags = null;
+ }
+
+ // Add the maxStalenessMS value to the read Preference
+ if(this.options && this.options.maxStalenessMS) {
+ this.maxStalenessMS = this.options.maxStalenessMS;
+ }
}
/**
@@ -56,7 +73,7 @@ var ReadPreference = function(mode, tags) {
* @method
* @param {string} mode The string representing the read preference mode.
* @return {boolean}
- */
+ */
ReadPreference.isValid = function(_mode) {
return (_mode == ReadPreference.PRIMARY || _mode == ReadPreference.PRIMARY_PREFERRED
|| _mode == ReadPreference.SECONDARY || _mode == ReadPreference.SECONDARY_PREFERRED
@@ -70,7 +87,7 @@ ReadPreference.isValid = function(_mode) {
* @method
* @param {string} mode The string representing the read preference mode.
* @return {boolean}
- */
+ */
ReadPreference.prototype.isValid = function(mode) {
var _mode = typeof mode == 'string' ? mode : this.mode;
return ReadPreference.isValid(_mode);
@@ -86,12 +103,23 @@ ReadPreference.prototype.toObject = function() {
object['tags'] = this.tags;
}
+ if(this.maxStalenessMS) {
+ object['maxStalenessMS'] = this.maxStalenessMS;
+ }
+
return object;
}
/**
* @ignore
*/
+ReadPreference.prototype.toJSON = function() {
+ return this.toObject();
+}
+
+/**
+ * @ignore
+ */
ReadPreference.PRIMARY = 'primary';
ReadPreference.PRIMARY_PREFERRED = 'primaryPreferred';
ReadPreference.SECONDARY = 'secondary';
@@ -101,4 +129,4 @@ ReadPreference.NEAREST = 'nearest'
/**
* @ignore
*/
-module.exports = ReadPreference; \ No newline at end of file
+module.exports = ReadPreference;