mongodb 3.2.5 → 3.3.0-beta2
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.
- package/HISTORY.md +0 -10
- package/index.js +4 -4
- package/lib/admin.js +56 -56
- package/lib/aggregation_cursor.js +7 -3
- package/lib/bulk/common.js +18 -13
- package/lib/change_stream.js +196 -89
- package/lib/collection.js +217 -169
- package/lib/command_cursor.js +17 -7
- package/lib/core/auth/auth_provider.js +158 -0
- package/lib/core/auth/defaultAuthProviders.js +29 -0
- package/lib/core/auth/gssapi.js +241 -0
- package/lib/core/auth/mongo_credentials.js +81 -0
- package/lib/core/auth/mongocr.js +51 -0
- package/lib/core/auth/plain.js +35 -0
- package/lib/core/auth/scram.js +293 -0
- package/lib/core/auth/sspi.js +131 -0
- package/lib/core/auth/x509.js +26 -0
- package/lib/core/connection/apm.js +236 -0
- package/lib/core/connection/command_result.js +36 -0
- package/lib/core/connection/commands.js +507 -0
- package/lib/core/connection/connect.js +370 -0
- package/lib/core/connection/connection.js +624 -0
- package/lib/core/connection/logger.js +246 -0
- package/lib/core/connection/msg.js +219 -0
- package/lib/core/connection/pool.js +1285 -0
- package/lib/core/connection/utils.js +57 -0
- package/lib/core/cursor.js +752 -0
- package/lib/core/error.js +186 -0
- package/lib/core/index.js +50 -0
- package/lib/core/sdam/monitoring.js +228 -0
- package/lib/core/sdam/server.js +467 -0
- package/lib/core/sdam/server_description.js +163 -0
- package/lib/core/sdam/server_selectors.js +244 -0
- package/lib/core/sdam/srv_polling.js +135 -0
- package/lib/core/sdam/topology.js +1151 -0
- package/lib/core/sdam/topology_description.js +408 -0
- package/lib/core/sessions.js +711 -0
- package/lib/core/tools/smoke_plugin.js +61 -0
- package/lib/core/topologies/mongos.js +1337 -0
- package/lib/core/topologies/read_preference.js +202 -0
- package/lib/core/topologies/replset.js +1507 -0
- package/lib/core/topologies/replset_state.js +1121 -0
- package/lib/core/topologies/server.js +984 -0
- package/lib/core/topologies/shared.js +453 -0
- package/lib/core/transactions.js +167 -0
- package/lib/core/uri_parser.js +631 -0
- package/lib/core/utils.js +165 -0
- package/lib/core/wireprotocol/command.js +170 -0
- package/lib/core/wireprotocol/compression.js +73 -0
- package/lib/core/wireprotocol/constants.js +13 -0
- package/lib/core/wireprotocol/get_more.js +86 -0
- package/lib/core/wireprotocol/index.js +18 -0
- package/lib/core/wireprotocol/kill_cursors.js +70 -0
- package/lib/core/wireprotocol/query.js +224 -0
- package/lib/core/wireprotocol/shared.js +115 -0
- package/lib/core/wireprotocol/write_command.js +50 -0
- package/lib/cursor.js +40 -46
- package/lib/db.js +141 -95
- package/lib/dynamic_loaders.js +32 -0
- package/lib/error.js +12 -10
- package/lib/gridfs/chunk.js +2 -2
- package/lib/gridfs/grid_store.js +31 -25
- package/lib/gridfs-stream/index.js +4 -4
- package/lib/gridfs-stream/upload.js +1 -1
- package/lib/mongo_client.js +37 -15
- package/lib/operations/add_user.js +96 -0
- package/lib/operations/aggregate.js +24 -13
- package/lib/operations/aggregate_operation.js +127 -0
- package/lib/operations/bulk_write.js +104 -0
- package/lib/operations/close.js +47 -0
- package/lib/operations/collection_ops.js +28 -287
- package/lib/operations/collections.js +55 -0
- package/lib/operations/command.js +120 -0
- package/lib/operations/command_v2.js +43 -0
- package/lib/operations/common_functions.js +372 -0
- package/lib/operations/{mongo_client_ops.js → connect.js} +185 -157
- package/lib/operations/count.js +72 -0
- package/lib/operations/count_documents.js +46 -0
- package/lib/operations/create_collection.js +118 -0
- package/lib/operations/create_index.js +92 -0
- package/lib/operations/create_indexes.js +61 -0
- package/lib/operations/cursor_ops.js +3 -4
- package/lib/operations/db_ops.js +15 -12
- package/lib/operations/delete_many.js +25 -0
- package/lib/operations/delete_one.js +25 -0
- package/lib/operations/distinct.js +85 -0
- package/lib/operations/drop.js +53 -0
- package/lib/operations/drop_index.js +42 -0
- package/lib/operations/drop_indexes.js +23 -0
- package/lib/operations/estimated_document_count.js +33 -0
- package/lib/operations/execute_db_admin_command.js +34 -0
- package/lib/operations/execute_operation.js +165 -0
- package/lib/operations/explain.js +23 -0
- package/lib/operations/find_and_modify.js +98 -0
- package/lib/operations/find_one.js +33 -0
- package/lib/operations/find_one_and_delete.js +16 -0
- package/lib/operations/find_one_and_replace.js +18 -0
- package/lib/operations/find_one_and_update.js +19 -0
- package/lib/operations/geo_haystack_search.js +79 -0
- package/lib/operations/has_next.js +40 -0
- package/lib/operations/index_exists.js +39 -0
- package/lib/operations/index_information.js +23 -0
- package/lib/operations/indexes.js +22 -0
- package/lib/operations/insert_many.js +63 -0
- package/lib/operations/insert_one.js +75 -0
- package/lib/operations/is_capped.js +19 -0
- package/lib/operations/list_indexes.js +66 -0
- package/lib/operations/map_reduce.js +189 -0
- package/lib/operations/next.js +32 -0
- package/lib/operations/operation.js +63 -0
- package/lib/operations/options_operation.js +32 -0
- package/lib/operations/profiling_level.js +31 -0
- package/lib/operations/re_index.js +28 -0
- package/lib/operations/remove_user.js +52 -0
- package/lib/operations/rename.js +61 -0
- package/lib/operations/replace_one.js +47 -0
- package/lib/operations/set_profiling_level.js +48 -0
- package/lib/operations/stats.js +45 -0
- package/lib/operations/to_array.js +68 -0
- package/lib/operations/update_many.js +29 -0
- package/lib/operations/update_one.js +44 -0
- package/lib/operations/validate_collection.js +40 -0
- package/lib/read_concern.js +55 -0
- package/lib/topologies/mongos.js +3 -3
- package/lib/topologies/native_topology.js +22 -2
- package/lib/topologies/replset.js +3 -3
- package/lib/topologies/server.js +4 -4
- package/lib/topologies/topology_base.js +6 -6
- package/lib/url_parser.js +4 -3
- package/lib/utils.js +46 -59
- package/lib/write_concern.js +66 -0
- package/package.json +15 -6
- package/lib/.DS_Store +0 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The **ReadPreference** class is a class that represents a MongoDB ReadPreference and is
|
|
5
|
+
* used to construct connections.
|
|
6
|
+
* @class
|
|
7
|
+
* @param {string} mode A string describing the read preference mode (primary|primaryPreferred|secondary|secondaryPreferred|nearest)
|
|
8
|
+
* @param {array} tags The tags object
|
|
9
|
+
* @param {object} [options] Additional read preference options
|
|
10
|
+
* @param {number} [options.maxStalenessSeconds] Max secondary read staleness in seconds, Minimum value is 90 seconds.
|
|
11
|
+
* @see https://docs.mongodb.com/manual/core/read-preference/
|
|
12
|
+
* @return {ReadPreference}
|
|
13
|
+
*/
|
|
14
|
+
const ReadPreference = function(mode, tags, options) {
|
|
15
|
+
if (!ReadPreference.isValid(mode)) {
|
|
16
|
+
throw new TypeError(`Invalid read preference mode ${mode}`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// TODO(major): tags MUST be an array of tagsets
|
|
20
|
+
if (tags && !Array.isArray(tags)) {
|
|
21
|
+
console.warn(
|
|
22
|
+
'ReadPreference tags must be an array, this will change in the next major version'
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
if (typeof tags.maxStalenessSeconds !== 'undefined') {
|
|
26
|
+
// this is likely an options object
|
|
27
|
+
options = tags;
|
|
28
|
+
tags = undefined;
|
|
29
|
+
} else {
|
|
30
|
+
tags = [tags];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
this.mode = mode;
|
|
35
|
+
this.tags = tags;
|
|
36
|
+
|
|
37
|
+
options = options || {};
|
|
38
|
+
if (options.maxStalenessSeconds != null) {
|
|
39
|
+
if (options.maxStalenessSeconds <= 0) {
|
|
40
|
+
throw new TypeError('maxStalenessSeconds must be a positive integer');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.maxStalenessSeconds = options.maxStalenessSeconds;
|
|
44
|
+
|
|
45
|
+
// NOTE: The minimum required wire version is 5 for this read preference. If the existing
|
|
46
|
+
// topology has a lower value then a MongoError will be thrown during server selection.
|
|
47
|
+
this.minWireVersion = 5;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (this.mode === ReadPreference.PRIMARY) {
|
|
51
|
+
if (this.tags && Array.isArray(this.tags) && this.tags.length > 0) {
|
|
52
|
+
throw new TypeError('Primary read preference cannot be combined with tags');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (this.maxStalenessSeconds) {
|
|
56
|
+
throw new TypeError('Primary read preference cannot be combined with maxStalenessSeconds');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Support the deprecated `preference` property introduced in the porcelain layer
|
|
62
|
+
Object.defineProperty(ReadPreference.prototype, 'preference', {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
get: function() {
|
|
65
|
+
return this.mode;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
* Read preference mode constants
|
|
71
|
+
*/
|
|
72
|
+
ReadPreference.PRIMARY = 'primary';
|
|
73
|
+
ReadPreference.PRIMARY_PREFERRED = 'primaryPreferred';
|
|
74
|
+
ReadPreference.SECONDARY = 'secondary';
|
|
75
|
+
ReadPreference.SECONDARY_PREFERRED = 'secondaryPreferred';
|
|
76
|
+
ReadPreference.NEAREST = 'nearest';
|
|
77
|
+
|
|
78
|
+
const VALID_MODES = [
|
|
79
|
+
ReadPreference.PRIMARY,
|
|
80
|
+
ReadPreference.PRIMARY_PREFERRED,
|
|
81
|
+
ReadPreference.SECONDARY,
|
|
82
|
+
ReadPreference.SECONDARY_PREFERRED,
|
|
83
|
+
ReadPreference.NEAREST,
|
|
84
|
+
null
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Construct a ReadPreference given an options object.
|
|
89
|
+
*
|
|
90
|
+
* @param {object} options The options object from which to extract the read preference.
|
|
91
|
+
* @return {ReadPreference}
|
|
92
|
+
*/
|
|
93
|
+
ReadPreference.fromOptions = function(options) {
|
|
94
|
+
const readPreference = options.readPreference;
|
|
95
|
+
const readPreferenceTags = options.readPreferenceTags;
|
|
96
|
+
|
|
97
|
+
if (readPreference == null) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (typeof readPreference === 'string') {
|
|
102
|
+
return new ReadPreference(readPreference, readPreferenceTags);
|
|
103
|
+
} else if (!(readPreference instanceof ReadPreference) && typeof readPreference === 'object') {
|
|
104
|
+
const mode = readPreference.mode || readPreference.preference;
|
|
105
|
+
if (mode && typeof mode === 'string') {
|
|
106
|
+
return new ReadPreference(mode, readPreference.tags, {
|
|
107
|
+
maxStalenessSeconds: readPreference.maxStalenessSeconds
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return readPreference;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Validate if a mode is legal
|
|
117
|
+
*
|
|
118
|
+
* @method
|
|
119
|
+
* @param {string} mode The string representing the read preference mode.
|
|
120
|
+
* @return {boolean} True if a mode is valid
|
|
121
|
+
*/
|
|
122
|
+
ReadPreference.isValid = function(mode) {
|
|
123
|
+
return VALID_MODES.indexOf(mode) !== -1;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Validate if a mode is legal
|
|
128
|
+
*
|
|
129
|
+
* @method
|
|
130
|
+
* @param {string} mode The string representing the read preference mode.
|
|
131
|
+
* @return {boolean} True if a mode is valid
|
|
132
|
+
*/
|
|
133
|
+
ReadPreference.prototype.isValid = function(mode) {
|
|
134
|
+
return ReadPreference.isValid(typeof mode === 'string' ? mode : this.mode);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const needSlaveOk = ['primaryPreferred', 'secondary', 'secondaryPreferred', 'nearest'];
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Indicates that this readPreference needs the "slaveOk" bit when sent over the wire
|
|
141
|
+
* @method
|
|
142
|
+
* @return {boolean}
|
|
143
|
+
* @see https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/#op-query
|
|
144
|
+
*/
|
|
145
|
+
ReadPreference.prototype.slaveOk = function() {
|
|
146
|
+
return needSlaveOk.indexOf(this.mode) !== -1;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Are the two read preference equal
|
|
151
|
+
* @method
|
|
152
|
+
* @param {ReadPreference} readPreference The read preference with which to check equality
|
|
153
|
+
* @return {boolean} True if the two ReadPreferences are equivalent
|
|
154
|
+
*/
|
|
155
|
+
ReadPreference.prototype.equals = function(readPreference) {
|
|
156
|
+
return readPreference.mode === this.mode;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Return JSON representation
|
|
161
|
+
* @method
|
|
162
|
+
* @return {Object} A JSON representation of the ReadPreference
|
|
163
|
+
*/
|
|
164
|
+
ReadPreference.prototype.toJSON = function() {
|
|
165
|
+
const readPreference = { mode: this.mode };
|
|
166
|
+
if (Array.isArray(this.tags)) readPreference.tags = this.tags;
|
|
167
|
+
if (this.maxStalenessSeconds) readPreference.maxStalenessSeconds = this.maxStalenessSeconds;
|
|
168
|
+
return readPreference;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Primary read preference
|
|
173
|
+
* @member
|
|
174
|
+
* @type {ReadPreference}
|
|
175
|
+
*/
|
|
176
|
+
ReadPreference.primary = new ReadPreference('primary');
|
|
177
|
+
/**
|
|
178
|
+
* Primary Preferred read preference
|
|
179
|
+
* @member
|
|
180
|
+
* @type {ReadPreference}
|
|
181
|
+
*/
|
|
182
|
+
ReadPreference.primaryPreferred = new ReadPreference('primaryPreferred');
|
|
183
|
+
/**
|
|
184
|
+
* Secondary read preference
|
|
185
|
+
* @member
|
|
186
|
+
* @type {ReadPreference}
|
|
187
|
+
*/
|
|
188
|
+
ReadPreference.secondary = new ReadPreference('secondary');
|
|
189
|
+
/**
|
|
190
|
+
* Secondary Preferred read preference
|
|
191
|
+
* @member
|
|
192
|
+
* @type {ReadPreference}
|
|
193
|
+
*/
|
|
194
|
+
ReadPreference.secondaryPreferred = new ReadPreference('secondaryPreferred');
|
|
195
|
+
/**
|
|
196
|
+
* Nearest read preference
|
|
197
|
+
* @member
|
|
198
|
+
* @type {ReadPreference}
|
|
199
|
+
*/
|
|
200
|
+
ReadPreference.nearest = new ReadPreference('nearest');
|
|
201
|
+
|
|
202
|
+
module.exports = ReadPreference;
|