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
package/lib/utils.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const MongoError = require('
|
|
4
|
-
const ReadPreference = require('
|
|
3
|
+
const MongoError = require('./core').MongoError;
|
|
4
|
+
const ReadPreference = require('./core').ReadPreference;
|
|
5
|
+
const WriteConcern = require('./write_concern');
|
|
5
6
|
|
|
6
7
|
var shallowClone = function(obj) {
|
|
7
8
|
var copy = {};
|
|
@@ -361,7 +362,7 @@ var mergeOptionsAndWriteConcern = function(targetOptions, sourceOptions, keys, m
|
|
|
361
362
|
* @param {array} args Arguments to apply the provided operation
|
|
362
363
|
* @param {object} [options] Options that modify the behavior of the method
|
|
363
364
|
*/
|
|
364
|
-
const
|
|
365
|
+
const executeLegacyOperation = (topology, operation, args, options) => {
|
|
365
366
|
if (topology == null) {
|
|
366
367
|
throw new TypeError('This method requires a valid topology instance');
|
|
367
368
|
}
|
|
@@ -422,7 +423,7 @@ const executeOperation = (topology, operation, args, options) => {
|
|
|
422
423
|
|
|
423
424
|
// Return a Promise
|
|
424
425
|
if (args[args.length - 1] != null) {
|
|
425
|
-
throw new TypeError('final argument to `
|
|
426
|
+
throw new TypeError('final argument to `executeLegacyOperation` must be a callback');
|
|
426
427
|
}
|
|
427
428
|
|
|
428
429
|
return new Promise(function(resolve, reject) {
|
|
@@ -474,26 +475,16 @@ function applyWriteConcern(target, sources, options) {
|
|
|
474
475
|
return target;
|
|
475
476
|
}
|
|
476
477
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
if (options.w != null) writeConcern.w = options.w;
|
|
480
|
-
if (options.wtimeout != null) writeConcern.wtimeout = options.wtimeout;
|
|
481
|
-
if (options.j != null) writeConcern.j = options.j;
|
|
482
|
-
if (options.fsync != null) writeConcern.fsync = options.fsync;
|
|
478
|
+
const writeConcern = WriteConcern.fromOptions(options);
|
|
479
|
+
if (writeConcern) {
|
|
483
480
|
return Object.assign(target, { writeConcern });
|
|
484
481
|
}
|
|
485
482
|
|
|
486
|
-
if (
|
|
487
|
-
coll &&
|
|
488
|
-
(coll.writeConcern.w != null || coll.writeConcern.j != null || coll.writeConcern.fsync != null)
|
|
489
|
-
) {
|
|
483
|
+
if (coll && coll.writeConcern) {
|
|
490
484
|
return Object.assign(target, { writeConcern: Object.assign({}, coll.writeConcern) });
|
|
491
485
|
}
|
|
492
486
|
|
|
493
|
-
if (
|
|
494
|
-
db &&
|
|
495
|
-
(db.writeConcern.w != null || db.writeConcern.j != null || db.writeConcern.fsync != null)
|
|
496
|
-
) {
|
|
487
|
+
if (db && db.writeConcern) {
|
|
497
488
|
return Object.assign(target, { writeConcern: Object.assign({}, db.writeConcern) });
|
|
498
489
|
}
|
|
499
490
|
|
|
@@ -505,56 +496,27 @@ function applyWriteConcern(target, sources, options) {
|
|
|
505
496
|
* determine the read preference (if there is one), but will also ensure the returned value is a
|
|
506
497
|
* properly constructed instance of `ReadPreference`.
|
|
507
498
|
*
|
|
499
|
+
* @param {Collection|Db|MongoClient} parent The parent of the operation on which to determine the read
|
|
500
|
+
* preference, used for determining the inherited read preference.
|
|
508
501
|
* @param {Object} options The options passed into the method, potentially containing a read preference
|
|
509
|
-
* @param {Object} sources Sources from which we can inherit a read preference
|
|
510
502
|
* @returns {(ReadPreference|null)} The resolved read preference
|
|
511
503
|
*/
|
|
512
|
-
function resolveReadPreference(
|
|
504
|
+
function resolveReadPreference(parent, options) {
|
|
513
505
|
options = options || {};
|
|
514
|
-
sources = sources || {};
|
|
515
|
-
|
|
516
|
-
const db = sources.db;
|
|
517
|
-
const coll = sources.collection;
|
|
518
|
-
const defaultReadPreference = sources.default;
|
|
519
506
|
const session = options.session;
|
|
520
507
|
|
|
508
|
+
const inheritedReadPreference = parent.readPreference;
|
|
509
|
+
|
|
521
510
|
let readPreference;
|
|
522
511
|
if (options.readPreference) {
|
|
523
|
-
readPreference = options
|
|
512
|
+
readPreference = ReadPreference.fromOptions(options);
|
|
524
513
|
} else if (session && session.inTransaction() && session.transaction.options.readPreference) {
|
|
525
514
|
// The transaction’s read preference MUST override all other user configurable read preferences.
|
|
526
515
|
readPreference = session.transaction.options.readPreference;
|
|
516
|
+
} else if (inheritedReadPreference != null) {
|
|
517
|
+
readPreference = inheritedReadPreference;
|
|
527
518
|
} else {
|
|
528
|
-
|
|
529
|
-
readPreference = coll.s.readPreference;
|
|
530
|
-
} else if (db && db.s.readPreference) {
|
|
531
|
-
readPreference = db.s.readPreference;
|
|
532
|
-
} else if (defaultReadPreference) {
|
|
533
|
-
readPreference = defaultReadPreference;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
// do we even have a read preference?
|
|
538
|
-
if (readPreference == null) {
|
|
539
|
-
return null;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
// now attempt to convert the read preference if necessary
|
|
543
|
-
if (typeof readPreference === 'string') {
|
|
544
|
-
readPreference = new ReadPreference(readPreference);
|
|
545
|
-
} else if (
|
|
546
|
-
readPreference &&
|
|
547
|
-
!(readPreference instanceof ReadPreference) &&
|
|
548
|
-
typeof readPreference === 'object'
|
|
549
|
-
) {
|
|
550
|
-
const mode = readPreference.mode || readPreference.preference;
|
|
551
|
-
if (mode && typeof mode === 'string') {
|
|
552
|
-
readPreference = new ReadPreference(mode, readPreference.tags, {
|
|
553
|
-
maxStalenessSeconds: readPreference.maxStalenessSeconds
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
} else if (!(readPreference instanceof ReadPreference)) {
|
|
557
|
-
throw new TypeError('Invalid read preference: ' + readPreference);
|
|
519
|
+
throw new Error('No readPreference was provided or inherited.');
|
|
558
520
|
}
|
|
559
521
|
|
|
560
522
|
return readPreference;
|
|
@@ -699,6 +661,30 @@ try {
|
|
|
699
661
|
SUPPORTS.ASYNC_ITERATOR = false;
|
|
700
662
|
}
|
|
701
663
|
|
|
664
|
+
class MongoDBNamespace {
|
|
665
|
+
constructor(db, collection) {
|
|
666
|
+
this.db = db;
|
|
667
|
+
this.collection = collection;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
toString() {
|
|
671
|
+
return this.collection ? `${this.db}.${this.collection}` : this.db;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
withCollection(collection) {
|
|
675
|
+
return new MongoDBNamespace(this.db, collection);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
static fromString(namespace) {
|
|
679
|
+
if (!namespace) {
|
|
680
|
+
throw new Error(`Cannot parse namespace from "${namespace}"`);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
const index = namespace.indexOf('.');
|
|
684
|
+
return new MongoDBNamespace(namespace.substring(0, index), namespace.substring(index + 1));
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
702
688
|
module.exports = {
|
|
703
689
|
filterOptions,
|
|
704
690
|
mergeOptions,
|
|
@@ -717,13 +703,14 @@ module.exports = {
|
|
|
717
703
|
MAX_JS_INT: Number.MAX_SAFE_INTEGER + 1,
|
|
718
704
|
mergeOptionsAndWriteConcern,
|
|
719
705
|
translateReadPreference,
|
|
720
|
-
|
|
706
|
+
executeLegacyOperation,
|
|
721
707
|
applyRetryableWrites,
|
|
722
708
|
applyWriteConcern,
|
|
723
|
-
resolveReadPreference,
|
|
724
709
|
isPromiseLike,
|
|
725
710
|
decorateWithCollation,
|
|
726
711
|
decorateWithReadConcern,
|
|
727
712
|
deprecateOptions,
|
|
728
|
-
SUPPORTS
|
|
713
|
+
SUPPORTS,
|
|
714
|
+
MongoDBNamespace,
|
|
715
|
+
resolveReadPreference
|
|
729
716
|
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The **WriteConcern** class is a class that represents a MongoDB WriteConcern.
|
|
5
|
+
* @class
|
|
6
|
+
* @property {(number|string)} w The write concern
|
|
7
|
+
* @property {number} wtimeout The write concern timeout
|
|
8
|
+
* @property {boolean} j The journal write concern
|
|
9
|
+
* @property {boolean} fsync The file sync write concern
|
|
10
|
+
* @see https://docs.mongodb.com/manual/reference/write-concern/index.html
|
|
11
|
+
*/
|
|
12
|
+
class WriteConcern {
|
|
13
|
+
/**
|
|
14
|
+
* Constructs a WriteConcern from the write concern properties.
|
|
15
|
+
* @param {(number|string)} [w] The write concern
|
|
16
|
+
* @param {number} [wtimeout] The write concern timeout
|
|
17
|
+
* @param {boolean} [j] The journal write concern
|
|
18
|
+
* @param {boolean} [fsync] The file sync write concern
|
|
19
|
+
*/
|
|
20
|
+
constructor(w, wtimeout, j, fsync) {
|
|
21
|
+
if (w != null) {
|
|
22
|
+
this.w = w;
|
|
23
|
+
}
|
|
24
|
+
if (wtimeout != null) {
|
|
25
|
+
this.wtimeout = wtimeout;
|
|
26
|
+
}
|
|
27
|
+
if (j != null) {
|
|
28
|
+
this.j = j;
|
|
29
|
+
}
|
|
30
|
+
if (fsync != null) {
|
|
31
|
+
this.fsync = fsync;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Construct a WriteConcern given an options object.
|
|
37
|
+
*
|
|
38
|
+
* @param {object} options The options object from which to extract the write concern.
|
|
39
|
+
* @return {WriteConcern}
|
|
40
|
+
*/
|
|
41
|
+
static fromOptions(options) {
|
|
42
|
+
if (
|
|
43
|
+
options == null ||
|
|
44
|
+
(options.writeConcern == null &&
|
|
45
|
+
options.w == null &&
|
|
46
|
+
options.wtimeout == null &&
|
|
47
|
+
options.j == null &&
|
|
48
|
+
options.fsync == null)
|
|
49
|
+
) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (options.writeConcern) {
|
|
54
|
+
return new WriteConcern(
|
|
55
|
+
options.writeConcern.w,
|
|
56
|
+
options.writeConcern.wtimeout,
|
|
57
|
+
options.writeConcern.j,
|
|
58
|
+
options.writeConcern.fsync
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return new WriteConcern(options.w, options.wtimeout, options.j, options.fsync);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = WriteConcern;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongodb",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0-beta2",
|
|
4
4
|
"description": "The official MongoDB driver for Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -16,13 +16,20 @@
|
|
|
16
16
|
"driver",
|
|
17
17
|
"official"
|
|
18
18
|
],
|
|
19
|
+
"peerOptionalDependencies": {
|
|
20
|
+
"kerberos": "^1.0.0",
|
|
21
|
+
"mongodb-client-encryption": "^1.0.0",
|
|
22
|
+
"mongodb-extjson": "^2.1.2",
|
|
23
|
+
"snappy": "^6.1.1",
|
|
24
|
+
"bson-ext": "^2.0.0"
|
|
25
|
+
},
|
|
19
26
|
"dependencies": {
|
|
20
|
-
"
|
|
27
|
+
"bson": "^1.1.1",
|
|
28
|
+
"require_optional": "^1.0.1",
|
|
21
29
|
"safe-buffer": "^5.1.2"
|
|
22
30
|
},
|
|
23
31
|
"devDependencies": {
|
|
24
32
|
"bluebird": "3.5.0",
|
|
25
|
-
"bson": "^1.0.4",
|
|
26
33
|
"chai": "^4.1.1",
|
|
27
34
|
"chai-subset": "^1.6.0",
|
|
28
35
|
"co": "4.6.0",
|
|
@@ -40,8 +47,10 @@
|
|
|
40
47
|
"semver": "^5.5.0",
|
|
41
48
|
"sinon": "^4.3.0",
|
|
42
49
|
"sinon-chai": "^3.2.0",
|
|
50
|
+
"snappy": "^6.1.2",
|
|
43
51
|
"standard-version": "^4.4.0",
|
|
44
|
-
"worker-farm": "^1.5.0"
|
|
52
|
+
"worker-farm": "^1.5.0",
|
|
53
|
+
"wtfnode": "^0.8.0"
|
|
45
54
|
},
|
|
46
55
|
"license": "Apache-2.0",
|
|
47
56
|
"engines": {
|
|
@@ -52,8 +61,8 @@
|
|
|
52
61
|
},
|
|
53
62
|
"scripts": {
|
|
54
63
|
"atlas": "node ./test/atlas_connectivity_tests.js",
|
|
55
|
-
"test": "npm run lint && mongodb-test-runner -t 60000 test/unit test/functional",
|
|
56
|
-
"coverage": "istanbul cover mongodb-test-runner -- -t 60000
|
|
64
|
+
"test": "npm run lint && mongodb-test-runner -t 60000 test/core test/unit test/functional",
|
|
65
|
+
"coverage": "istanbul cover mongodb-test-runner -- -t 60000 test/core test/unit test/functional",
|
|
57
66
|
"lint": "eslint lib test",
|
|
58
67
|
"format": "prettier --print-width 100 --tab-width 2 --single-quote --write 'test/**/*.js' 'lib/**/*.js'",
|
|
59
68
|
"bench": "node test/driverBench/",
|
package/lib/.DS_Store
DELETED
|
Binary file
|