mongodb 3.1.6 → 3.1.10
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 +56 -0
- package/{LICENSE → LICENSE.md} +0 -0
- package/README.md +10 -3
- package/lib/collection.js +37 -31
- package/lib/constants.js +10 -0
- package/lib/db.js +8 -7
- package/lib/gridfs-stream/upload.js +3 -3
- package/lib/mongo_client.js +1 -1
- package/lib/operations/collection_ops.js +37 -8
- package/lib/operations/cursor_ops.js +6 -1
- package/lib/operations/db_ops.js +8 -4
- package/lib/operations/mongo_client_ops.js +11 -1
- package/lib/utils.js +5 -5
- package/package.json +2 -3
package/HISTORY.md
CHANGED
|
@@ -2,6 +2,62 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
<a name="3.1.10"></a>
|
|
6
|
+
## [3.1.10](https://github.com/mongodb/node-mongodb-native/compare/v3.1.9...v3.1.10) (2018-11-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **auth:** remember to default to admin database ([c7dec28](https://github.com/mongodb/node-mongodb-native/commit/c7dec28))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* **core:** update to mongodb-core v3.1.9 ([bd3355b](https://github.com/mongodb/node-mongodb-native/commit/bd3355b))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
<a name="3.1.9"></a>
|
|
21
|
+
## [3.1.9](https://github.com/mongodb/node-mongodb-native/compare/v3.1.8...v3.1.9) (2018-11-06)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* **db:** move db constants to other file to avoid circular ref ([#1858](https://github.com/mongodb/node-mongodb-native/issues/1858)) ([239036f](https://github.com/mongodb/node-mongodb-native/commit/239036f))
|
|
27
|
+
* **estimated-document-count:** support options other than maxTimeMs ([36c3c7d](https://github.com/mongodb/node-mongodb-native/commit/36c3c7d))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
* **core:** update to mongodb-core v3.1.8 ([80d7c79](https://github.com/mongodb/node-mongodb-native/commit/80d7c79))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
<a name="3.1.8"></a>
|
|
37
|
+
## [3.1.8](https://github.com/mongodb/node-mongodb-native/compare/v3.1.7...v3.1.8) (2018-10-10)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### Bug Fixes
|
|
41
|
+
|
|
42
|
+
* **connect:** use reported default databse from new uri parser ([811f8f8](https://github.com/mongodb/node-mongodb-native/commit/811f8f8))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### Features
|
|
46
|
+
|
|
47
|
+
* **core:** update to mongodb-core v3.1.7 ([dbfc905](https://github.com/mongodb/node-mongodb-native/commit/dbfc905))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
<a name="3.1.7"></a>
|
|
52
|
+
## [3.1.7](https://github.com/mongodb/node-mongodb-native/compare/v3.1.6...v3.1.7) (2018-10-09)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
### Features
|
|
56
|
+
|
|
57
|
+
* **core:** update mongodb-core to v3.1.6 ([61b054e](https://github.com/mongodb/node-mongodb-native/commit/61b054e))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
5
61
|
<a name="3.1.6"></a>
|
|
6
62
|
## [3.1.6](https://github.com/mongodb/node-mongodb-native/compare/v3.1.5...v3.1.6) (2018-09-15)
|
|
7
63
|
|
package/{LICENSE → LICENSE.md}
RENAMED
|
File without changes
|
package/README.md
CHANGED
|
@@ -211,7 +211,7 @@ The application should print **Connected successfully to server** to the console
|
|
|
211
211
|
### Insert a Document
|
|
212
212
|
|
|
213
213
|
Add to **app.js** the following function which uses the **insertMany**
|
|
214
|
-
method to add three documents to the **documents** collection.
|
|
214
|
+
method to add three documents to the **documents** collection.
|
|
215
215
|
|
|
216
216
|
```js
|
|
217
217
|
const insertDocuments = function(db, callback) {
|
|
@@ -354,7 +354,7 @@ const updateDocument = function(db, callback) {
|
|
|
354
354
|
assert.equal(1, result.result.n);
|
|
355
355
|
console.log("Updated the document with the field a equal to 2");
|
|
356
356
|
callback(result);
|
|
357
|
-
});
|
|
357
|
+
});
|
|
358
358
|
}
|
|
359
359
|
```
|
|
360
360
|
|
|
@@ -399,7 +399,7 @@ const removeDocument = function(db, callback) {
|
|
|
399
399
|
assert.equal(1, result.result.n);
|
|
400
400
|
console.log("Removed the document with the field a equal to 3");
|
|
401
401
|
callback(result);
|
|
402
|
-
});
|
|
402
|
+
});
|
|
403
403
|
}
|
|
404
404
|
```
|
|
405
405
|
|
|
@@ -484,3 +484,10 @@ For more detailed information, see the [tutorials](docs/reference/content/tutori
|
|
|
484
484
|
* [MongoDB Documentation](http://mongodb.org)
|
|
485
485
|
* [Read about Schemas](http://learnmongodbthehardway.com)
|
|
486
486
|
* [Star us on GitHub](https://github.com/mongodb/node-mongodb-native)
|
|
487
|
+
|
|
488
|
+
## License
|
|
489
|
+
|
|
490
|
+
[Apache 2.0](LICENSE.md)
|
|
491
|
+
|
|
492
|
+
© 2009-2012 Christian Amor Kvalheim
|
|
493
|
+
© 2012-present MongoDB [Contributors](CONTRIBUTORS.md)
|
package/lib/collection.js
CHANGED
|
@@ -9,6 +9,7 @@ const MongoError = require('mongodb-core').MongoError;
|
|
|
9
9
|
const toError = require('./utils').toError;
|
|
10
10
|
const normalizeHintField = require('./utils').normalizeHintField;
|
|
11
11
|
const handleCallback = require('./utils').handleCallback;
|
|
12
|
+
const decorateCommand = require('./utils').decorateCommand;
|
|
12
13
|
const decorateWithCollation = require('./utils').decorateWithCollation;
|
|
13
14
|
const decorateWithReadConcern = require('./utils').decorateWithReadConcern;
|
|
14
15
|
const formattedOrderClause = require('./utils').formattedOrderClause;
|
|
@@ -390,12 +391,7 @@ Collection.prototype.find = deprecateOptions(
|
|
|
390
391
|
// Translate to new command option noCursorTimeout
|
|
391
392
|
if (typeof newOptions.timeout === 'boolean') newOptions.noCursorTimeout = newOptions.timeout;
|
|
392
393
|
|
|
393
|
-
|
|
394
|
-
for (let name in newOptions) {
|
|
395
|
-
if (newOptions[name] != null && name !== 'session') {
|
|
396
|
-
findCommand[name] = newOptions[name];
|
|
397
|
-
}
|
|
398
|
-
}
|
|
394
|
+
decorateCommand(findCommand, newOptions, ['session', 'collation']);
|
|
399
395
|
|
|
400
396
|
if (projection) findCommand.fields = projection;
|
|
401
397
|
|
|
@@ -424,7 +420,12 @@ Collection.prototype.find = deprecateOptions(
|
|
|
424
420
|
decorateWithReadConcern(findCommand, this, options);
|
|
425
421
|
|
|
426
422
|
// Decorate find command with collation options
|
|
427
|
-
|
|
423
|
+
try {
|
|
424
|
+
decorateWithCollation(findCommand, this, options);
|
|
425
|
+
} catch (err) {
|
|
426
|
+
if (typeof callback === 'function') return callback(err, null);
|
|
427
|
+
throw err;
|
|
428
|
+
}
|
|
428
429
|
|
|
429
430
|
const cursor = this.s.topology.cursor(this.s.namespace, findCommand, newOptions);
|
|
430
431
|
|
|
@@ -677,7 +678,7 @@ Collection.prototype.insert = deprecate(function(docs, options, callback) {
|
|
|
677
678
|
|
|
678
679
|
/**
|
|
679
680
|
* @typedef {Object} Collection~updateWriteOpResult
|
|
680
|
-
* @property {Object} result The raw result returned from MongoDB
|
|
681
|
+
* @property {Object} result The raw result returned from MongoDB. Will vary depending on server version.
|
|
681
682
|
* @property {Number} result.ok Is 1 if the command executed correctly.
|
|
682
683
|
* @property {Number} result.n The total count of documents scanned.
|
|
683
684
|
* @property {Number} result.nModified The total count of documents modified.
|
|
@@ -687,6 +688,8 @@ Collection.prototype.insert = deprecate(function(docs, options, callback) {
|
|
|
687
688
|
* @property {Number} upsertedCount The number of documents upserted.
|
|
688
689
|
* @property {Object} upsertedId The upserted id.
|
|
689
690
|
* @property {ObjectId} upsertedId._id The upserted _id returned from the server.
|
|
691
|
+
* @property {Object} message
|
|
692
|
+
* @property {Array} ops
|
|
690
693
|
*/
|
|
691
694
|
|
|
692
695
|
/**
|
|
@@ -697,7 +700,7 @@ Collection.prototype.insert = deprecate(function(docs, options, callback) {
|
|
|
697
700
|
*/
|
|
698
701
|
|
|
699
702
|
/**
|
|
700
|
-
* Update a single document
|
|
703
|
+
* Update a single document in a collection
|
|
701
704
|
* @method
|
|
702
705
|
* @param {object} filter The Filter used to select the document to update
|
|
703
706
|
* @param {object} update The update operations to be applied to the document
|
|
@@ -734,9 +737,9 @@ Collection.prototype.updateOne = function(filter, update, options, callback) {
|
|
|
734
737
|
};
|
|
735
738
|
|
|
736
739
|
/**
|
|
737
|
-
* Replace a document
|
|
740
|
+
* Replace a document in a collection with another document
|
|
738
741
|
* @method
|
|
739
|
-
* @param {object} filter The Filter used to select the document to
|
|
742
|
+
* @param {object} filter The Filter used to select the document to replace
|
|
740
743
|
* @param {object} doc The Document that replaces the matching document
|
|
741
744
|
* @param {object} [options] Optional settings.
|
|
742
745
|
* @param {boolean} [options.upsert=false] Update operation is an upsert.
|
|
@@ -746,7 +749,7 @@ Collection.prototype.updateOne = function(filter, update, options, callback) {
|
|
|
746
749
|
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
|
|
747
750
|
* @param {ClientSession} [options.session] optional session to use for this operation
|
|
748
751
|
* @param {Collection~updateWriteOpCallback} [callback] The command result callback
|
|
749
|
-
* @return {Promise} returns Promise if no callback passed
|
|
752
|
+
* @return {Promise<Collection~updatewriteOpResultObject>} returns Promise if no callback passed
|
|
750
753
|
*/
|
|
751
754
|
Collection.prototype.replaceOne = function(filter, doc, options, callback) {
|
|
752
755
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
@@ -762,10 +765,10 @@ Collection.prototype.replaceOne = function(filter, doc, options, callback) {
|
|
|
762
765
|
};
|
|
763
766
|
|
|
764
767
|
/**
|
|
765
|
-
* Update multiple documents
|
|
768
|
+
* Update multiple documents in a collection
|
|
766
769
|
* @method
|
|
767
770
|
* @param {object} filter The Filter used to select the documents to update
|
|
768
|
-
* @param {object} update The update operations to be applied to the
|
|
771
|
+
* @param {object} update The update operations to be applied to the documents
|
|
769
772
|
* @param {object} [options] Optional settings.
|
|
770
773
|
* @param {boolean} [options.upsert=false] Update operation is an upsert.
|
|
771
774
|
* @param {(number|string)} [options.w] The write concern.
|
|
@@ -774,7 +777,7 @@ Collection.prototype.replaceOne = function(filter, doc, options, callback) {
|
|
|
774
777
|
* @param {Array} [options.arrayFilters] optional list of array filters referenced in filtered positional operators
|
|
775
778
|
* @param {ClientSession} [options.session] optional session to use for this operation
|
|
776
779
|
* @param {Collection~updateWriteOpCallback} [callback] The command result callback
|
|
777
|
-
* @return {Promise} returns Promise if no callback passed
|
|
780
|
+
* @return {Promise<Collection~updateWriteOpResultObject>} returns Promise if no callback passed
|
|
778
781
|
*/
|
|
779
782
|
Collection.prototype.updateMany = function(filter, update, options, callback) {
|
|
780
783
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
@@ -838,7 +841,7 @@ Collection.prototype.update = deprecate(function(selector, document, options, ca
|
|
|
838
841
|
|
|
839
842
|
/**
|
|
840
843
|
* @typedef {Object} Collection~deleteWriteOpResult
|
|
841
|
-
* @property {Object} result The raw result returned from MongoDB
|
|
844
|
+
* @property {Object} result The raw result returned from MongoDB. Will vary depending on server version.
|
|
842
845
|
* @property {Number} result.ok Is 1 if the command executed correctly.
|
|
843
846
|
* @property {Number} result.n The total count of documents deleted.
|
|
844
847
|
* @property {Object} connection The connection object used for the operation.
|
|
@@ -853,7 +856,7 @@ Collection.prototype.update = deprecate(function(selector, document, options, ca
|
|
|
853
856
|
*/
|
|
854
857
|
|
|
855
858
|
/**
|
|
856
|
-
* Delete a document
|
|
859
|
+
* Delete a document from a collection
|
|
857
860
|
* @method
|
|
858
861
|
* @param {object} filter The Filter used to select the document to remove
|
|
859
862
|
* @param {object} [options] Optional settings.
|
|
@@ -880,7 +883,7 @@ Collection.prototype.deleteOne = function(filter, options, callback) {
|
|
|
880
883
|
Collection.prototype.removeOne = Collection.prototype.deleteOne;
|
|
881
884
|
|
|
882
885
|
/**
|
|
883
|
-
* Delete multiple documents
|
|
886
|
+
* Delete multiple documents from a collection
|
|
884
887
|
* @method
|
|
885
888
|
* @param {object} filter The Filter used to select the documents to remove
|
|
886
889
|
* @param {object} [options] Optional settings.
|
|
@@ -1386,8 +1389,6 @@ Collection.prototype.estimatedDocumentCount = function(options, callback) {
|
|
|
1386
1389
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
1387
1390
|
options = options || {};
|
|
1388
1391
|
|
|
1389
|
-
options = typeof options.maxTimeMS === 'number' ? options : {};
|
|
1390
|
-
|
|
1391
1392
|
return executeOperation(this.s.topology, count, [this, null, options, callback]);
|
|
1392
1393
|
};
|
|
1393
1394
|
|
|
@@ -1507,17 +1508,17 @@ Collection.prototype.stats = function(options, callback) {
|
|
|
1507
1508
|
*/
|
|
1508
1509
|
|
|
1509
1510
|
/**
|
|
1510
|
-
* Find a document and delete it in one atomic operation
|
|
1511
|
+
* Find a document and delete it in one atomic operation. Requires a write lock for the duration of the operation.
|
|
1511
1512
|
*
|
|
1512
1513
|
* @method
|
|
1513
|
-
* @param {object} filter
|
|
1514
|
+
* @param {object} filter The Filter used to select the document to remove
|
|
1514
1515
|
* @param {object} [options] Optional settings.
|
|
1515
1516
|
* @param {object} [options.projection] Limits the fields to return for all matching documents.
|
|
1516
1517
|
* @param {object} [options.sort] Determines which document the operation modifies if the query selects multiple documents.
|
|
1517
1518
|
* @param {number} [options.maxTimeMS] The maximum amount of time to allow the query to run.
|
|
1518
1519
|
* @param {ClientSession} [options.session] optional session to use for this operation
|
|
1519
1520
|
* @param {Collection~findAndModifyCallback} [callback] The collection result callback
|
|
1520
|
-
* @return {Promise} returns Promise if no callback passed
|
|
1521
|
+
* @return {Promise<Collection~findAndModifyWriteOpResultObject>} returns Promise if no callback passed
|
|
1521
1522
|
*/
|
|
1522
1523
|
Collection.prototype.findOneAndDelete = function(filter, options, callback) {
|
|
1523
1524
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
@@ -1531,11 +1532,11 @@ Collection.prototype.findOneAndDelete = function(filter, options, callback) {
|
|
|
1531
1532
|
};
|
|
1532
1533
|
|
|
1533
1534
|
/**
|
|
1534
|
-
* Find a document and replace it in one atomic operation
|
|
1535
|
+
* Find a document and replace it in one atomic operation. Requires a write lock for the duration of the operation.
|
|
1535
1536
|
*
|
|
1536
1537
|
* @method
|
|
1537
|
-
* @param {object} filter
|
|
1538
|
-
* @param {object} replacement Document
|
|
1538
|
+
* @param {object} filter The Filter used to select the document to replace
|
|
1539
|
+
* @param {object} replacement The Document that replaces the matching document
|
|
1539
1540
|
* @param {object} [options] Optional settings.
|
|
1540
1541
|
* @param {object} [options.projection] Limits the fields to return for all matching documents.
|
|
1541
1542
|
* @param {object} [options.sort] Determines which document the operation modifies if the query selects multiple documents.
|
|
@@ -1544,7 +1545,7 @@ Collection.prototype.findOneAndDelete = function(filter, options, callback) {
|
|
|
1544
1545
|
* @param {boolean} [options.returnOriginal=true] When false, returns the updated document rather than the original. The default is true.
|
|
1545
1546
|
* @param {ClientSession} [options.session] optional session to use for this operation
|
|
1546
1547
|
* @param {Collection~findAndModifyCallback} [callback] The collection result callback
|
|
1547
|
-
* @return {Promise} returns Promise if no callback passed
|
|
1548
|
+
* @return {Promise<Collection~findAndModifyWriteOpResultObject>} returns Promise if no callback passed
|
|
1548
1549
|
*/
|
|
1549
1550
|
Collection.prototype.findOneAndReplace = function(filter, replacement, options, callback) {
|
|
1550
1551
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
@@ -1566,10 +1567,10 @@ Collection.prototype.findOneAndReplace = function(filter, replacement, options,
|
|
|
1566
1567
|
};
|
|
1567
1568
|
|
|
1568
1569
|
/**
|
|
1569
|
-
* Find a document and update it in one atomic operation
|
|
1570
|
+
* Find a document and update it in one atomic operation. Requires a write lock for the duration of the operation.
|
|
1570
1571
|
*
|
|
1571
1572
|
* @method
|
|
1572
|
-
* @param {object} filter
|
|
1573
|
+
* @param {object} filter The Filter used to select the document to update
|
|
1573
1574
|
* @param {object} update Update operations to be performed on the document
|
|
1574
1575
|
* @param {object} [options] Optional settings.
|
|
1575
1576
|
* @param {object} [options.projection] Limits the fields to return for all matching documents.
|
|
@@ -1580,7 +1581,7 @@ Collection.prototype.findOneAndReplace = function(filter, replacement, options,
|
|
|
1580
1581
|
* @param {ClientSession} [options.session] optional session to use for this operation
|
|
1581
1582
|
* @param {Array} [options.arrayFilters] optional list of array filters referenced in filtered positional operators
|
|
1582
1583
|
* @param {Collection~findAndModifyCallback} [callback] The collection result callback
|
|
1583
|
-
* @return {Promise} returns Promise if no callback passed
|
|
1584
|
+
* @return {Promise<Collection~findAndModifyWriteOpResultObject>} returns Promise if no callback passed
|
|
1584
1585
|
*/
|
|
1585
1586
|
Collection.prototype.findOneAndUpdate = function(filter, update, options, callback) {
|
|
1586
1587
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
@@ -1756,7 +1757,12 @@ Collection.prototype.aggregate = function(pipeline, options, callback) {
|
|
|
1756
1757
|
}
|
|
1757
1758
|
|
|
1758
1759
|
// Have we specified collation
|
|
1759
|
-
|
|
1760
|
+
try {
|
|
1761
|
+
decorateWithCollation(command, this, options);
|
|
1762
|
+
} catch (err) {
|
|
1763
|
+
if (typeof callback === 'function') return callback(err, null);
|
|
1764
|
+
throw err;
|
|
1765
|
+
}
|
|
1760
1766
|
|
|
1761
1767
|
// If we have bypassDocumentValidation set
|
|
1762
1768
|
if (options.bypassDocumentValidation === true) {
|
package/lib/constants.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
SYSTEM_NAMESPACE_COLLECTION: 'system.namespaces',
|
|
5
|
+
SYSTEM_INDEX_COLLECTION: 'system.indexes',
|
|
6
|
+
SYSTEM_PROFILE_COLLECTION: 'system.profile',
|
|
7
|
+
SYSTEM_USER_COLLECTION: 'system.users',
|
|
8
|
+
SYSTEM_COMMAND_COLLECTION: '$cmd',
|
|
9
|
+
SYSTEM_JS_COLLECTION: 'system.js'
|
|
10
|
+
};
|
package/lib/db.js
CHANGED
|
@@ -19,6 +19,7 @@ const resolveReadPreference = require('./utils').resolveReadPreference;
|
|
|
19
19
|
const ChangeStream = require('./change_stream');
|
|
20
20
|
const deprecate = require('util').deprecate;
|
|
21
21
|
const deprecateOptions = require('./utils').deprecateOptions;
|
|
22
|
+
const CONSTANTS = require('./constants');
|
|
22
23
|
|
|
23
24
|
// Operations
|
|
24
25
|
const addUser = require('./operations/db_ops').addUser;
|
|
@@ -532,7 +533,7 @@ Db.prototype.listCollections = function(filter, options) {
|
|
|
532
533
|
// Return options
|
|
533
534
|
const _options = { transforms: listCollectionsTransforms(this.s.databaseName) };
|
|
534
535
|
// Get the cursor
|
|
535
|
-
cursor = this.collection(
|
|
536
|
+
cursor = this.collection(CONSTANTS.SYSTEM_NAMESPACE_COLLECTION).find(filter, _options);
|
|
536
537
|
// Do we have a readPreference, apply it
|
|
537
538
|
if (options.readPreference) cursor.setReadPreference(options.readPreference);
|
|
538
539
|
// Set the passed in batch size if one was provided
|
|
@@ -974,11 +975,11 @@ Db.prototype.getLogger = function() {
|
|
|
974
975
|
*/
|
|
975
976
|
|
|
976
977
|
// Constants
|
|
977
|
-
Db.SYSTEM_NAMESPACE_COLLECTION =
|
|
978
|
-
Db.SYSTEM_INDEX_COLLECTION =
|
|
979
|
-
Db.SYSTEM_PROFILE_COLLECTION =
|
|
980
|
-
Db.SYSTEM_USER_COLLECTION =
|
|
981
|
-
Db.SYSTEM_COMMAND_COLLECTION =
|
|
982
|
-
Db.SYSTEM_JS_COLLECTION =
|
|
978
|
+
Db.SYSTEM_NAMESPACE_COLLECTION = CONSTANTS.SYSTEM_NAMESPACE_COLLECTION;
|
|
979
|
+
Db.SYSTEM_INDEX_COLLECTION = CONSTANTS.SYSTEM_INDEX_COLLECTION;
|
|
980
|
+
Db.SYSTEM_PROFILE_COLLECTION = CONSTANTS.SYSTEM_PROFILE_COLLECTION;
|
|
981
|
+
Db.SYSTEM_USER_COLLECTION = CONSTANTS.SYSTEM_USER_COLLECTION;
|
|
982
|
+
Db.SYSTEM_COMMAND_COLLECTION = CONSTANTS.SYSTEM_COMMAND_COLLECTION;
|
|
983
|
+
Db.SYSTEM_JS_COLLECTION = CONSTANTS.SYSTEM_JS_COLLECTION;
|
|
983
984
|
|
|
984
985
|
module.exports = Db;
|
|
@@ -277,7 +277,7 @@ function checkDone(_this, callback) {
|
|
|
277
277
|
return false;
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
-
_this.files.
|
|
280
|
+
_this.files.insertOne(filesDoc, getWriteOptions(_this), function(error) {
|
|
281
281
|
if (error) {
|
|
282
282
|
return __handleError(_this, error, callback);
|
|
283
283
|
}
|
|
@@ -430,7 +430,7 @@ function doWrite(_this, chunk, encoding, callback) {
|
|
|
430
430
|
return false;
|
|
431
431
|
}
|
|
432
432
|
|
|
433
|
-
_this.chunks.
|
|
433
|
+
_this.chunks.insertOne(doc, getWriteOptions(_this), function(error) {
|
|
434
434
|
if (error) {
|
|
435
435
|
return __handleError(_this, error);
|
|
436
436
|
}
|
|
@@ -514,7 +514,7 @@ function writeRemnant(_this, callback) {
|
|
|
514
514
|
return false;
|
|
515
515
|
}
|
|
516
516
|
|
|
517
|
-
_this.chunks.
|
|
517
|
+
_this.chunks.insertOne(doc, getWriteOptions(_this), function(error) {
|
|
518
518
|
if (error) {
|
|
519
519
|
return __handleError(_this, error);
|
|
520
520
|
}
|
package/lib/mongo_client.js
CHANGED
|
@@ -109,7 +109,7 @@ const validOptions = require('./operations/mongo_client_ops').validOptions;
|
|
|
109
109
|
* @param {boolean} [options.auto_reconnect=true] Enable auto reconnecting for single server instances
|
|
110
110
|
* @param {boolean} [options.monitorCommands=false] Enable command monitoring for this client
|
|
111
111
|
* @param {number} [options.minSize] If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections
|
|
112
|
-
* @param {boolean} [options.useNewUrlParser=false] Determines whether or not to use the new url parser
|
|
112
|
+
* @param {boolean} [options.useNewUrlParser=false] Determines whether or not to use the new url parser. Enables the new, spec-compliant, url parser shipped in the core driver. This url parser fixes a number of problems with the original parser, and aims to outright replace that parser in the near future.
|
|
113
113
|
* @param {MongoClient~connectCallback} [callback] The command result callback
|
|
114
114
|
* @return {MongoClient} a MongoClient instance
|
|
115
115
|
*/
|
|
@@ -181,7 +181,12 @@ function count(coll, query, options, callback) {
|
|
|
181
181
|
collection: coll
|
|
182
182
|
});
|
|
183
183
|
|
|
184
|
-
|
|
184
|
+
let cmd;
|
|
185
|
+
try {
|
|
186
|
+
cmd = buildCountCommand(coll, query, options);
|
|
187
|
+
} catch (err) {
|
|
188
|
+
return callback(err);
|
|
189
|
+
}
|
|
185
190
|
|
|
186
191
|
executeCommand(coll.s.db, cmd, options, (err, result) => {
|
|
187
192
|
if (err) return handleCallback(callback, err);
|
|
@@ -390,7 +395,11 @@ function distinct(coll, key, query, options, callback) {
|
|
|
390
395
|
decorateWithReadConcern(cmd, coll, options);
|
|
391
396
|
|
|
392
397
|
// Have we specified collation
|
|
393
|
-
|
|
398
|
+
try {
|
|
399
|
+
decorateWithCollation(cmd, coll, options);
|
|
400
|
+
} catch (err) {
|
|
401
|
+
return callback(err, null);
|
|
402
|
+
}
|
|
394
403
|
|
|
395
404
|
// Execute the command
|
|
396
405
|
executeCommand(coll.s.db, cmd, options, (err, result) => {
|
|
@@ -521,7 +530,11 @@ function findAndModify(coll, query, sort, doc, options, callback) {
|
|
|
521
530
|
finalOptions.readPreference = ReadPreference.primary;
|
|
522
531
|
|
|
523
532
|
// Have we specified collation
|
|
524
|
-
|
|
533
|
+
try {
|
|
534
|
+
decorateWithCollation(queryObject, coll, finalOptions);
|
|
535
|
+
} catch (err) {
|
|
536
|
+
return callback(err, null);
|
|
537
|
+
}
|
|
525
538
|
|
|
526
539
|
// Execute the command
|
|
527
540
|
executeCommand(coll.s.db, queryObject, finalOptions, (err, result) => {
|
|
@@ -651,7 +664,7 @@ function geoHaystackSearch(coll, x, y, options, callback) {
|
|
|
651
664
|
};
|
|
652
665
|
|
|
653
666
|
// Remove read preference from hash if it exists
|
|
654
|
-
commandObject = decorateCommand(commandObject, options,
|
|
667
|
+
commandObject = decorateCommand(commandObject, options, ['readPreference', 'session']);
|
|
655
668
|
|
|
656
669
|
options = Object.assign({}, options);
|
|
657
670
|
// Ensure we have the right read preference inheritance
|
|
@@ -721,7 +734,11 @@ function group(coll, keys, condition, initial, reduce, finalize, command, option
|
|
|
721
734
|
decorateWithReadConcern(selector, coll, options);
|
|
722
735
|
|
|
723
736
|
// Have we specified collation
|
|
724
|
-
|
|
737
|
+
try {
|
|
738
|
+
decorateWithCollation(selector, coll, options);
|
|
739
|
+
} catch (err) {
|
|
740
|
+
return callback(err, null);
|
|
741
|
+
}
|
|
725
742
|
|
|
726
743
|
// Execute command
|
|
727
744
|
executeCommand(coll.s.db, selector, options, (err, result) => {
|
|
@@ -933,7 +950,11 @@ function mapReduce(coll, map, reduce, options, callback) {
|
|
|
933
950
|
}
|
|
934
951
|
|
|
935
952
|
// Have we specified collation
|
|
936
|
-
|
|
953
|
+
try {
|
|
954
|
+
decorateWithCollation(mapCommandHash, coll, options);
|
|
955
|
+
} catch (err) {
|
|
956
|
+
return callback(err, null);
|
|
957
|
+
}
|
|
937
958
|
|
|
938
959
|
// Execute command
|
|
939
960
|
executeCommand(coll.s.db, mapCommandHash, options, (err, result) => {
|
|
@@ -1154,7 +1175,11 @@ function removeDocuments(coll, selector, options, callback) {
|
|
|
1154
1175
|
}
|
|
1155
1176
|
|
|
1156
1177
|
// Have we specified collation
|
|
1157
|
-
|
|
1178
|
+
try {
|
|
1179
|
+
decorateWithCollation(finalOptions, coll, options);
|
|
1180
|
+
} catch (err) {
|
|
1181
|
+
return callback(err, null);
|
|
1182
|
+
}
|
|
1158
1183
|
|
|
1159
1184
|
// Execute the remove
|
|
1160
1185
|
coll.s.topology.remove(coll.s.namespace, [op], finalOptions, (err, result) => {
|
|
@@ -1358,7 +1383,11 @@ function updateDocuments(coll, selector, document, options, callback) {
|
|
|
1358
1383
|
}
|
|
1359
1384
|
|
|
1360
1385
|
// Have we specified collation
|
|
1361
|
-
|
|
1386
|
+
try {
|
|
1387
|
+
decorateWithCollation(finalOptions, coll, options);
|
|
1388
|
+
} catch (err) {
|
|
1389
|
+
return callback(err, null);
|
|
1390
|
+
}
|
|
1362
1391
|
|
|
1363
1392
|
// Update options
|
|
1364
1393
|
coll.s.topology.update(coll.s.namespace, [op], finalOptions, (err, result) => {
|
|
@@ -44,7 +44,12 @@ function count(cursor, applySkipLimit, opts, callback) {
|
|
|
44
44
|
const delimiter = cursor.s.ns.indexOf('.');
|
|
45
45
|
options.collectionName = cursor.s.ns.substr(delimiter + 1);
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
let command;
|
|
48
|
+
try {
|
|
49
|
+
command = buildCountCommand(cursor, cursor.s.cmd.query, options);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
return callback(err);
|
|
52
|
+
}
|
|
48
53
|
|
|
49
54
|
// Set cursor server to the same as the topology
|
|
50
55
|
cursor.server = cursor.topology.s.coreTopology;
|
package/lib/operations/db_ops.js
CHANGED
|
@@ -4,13 +4,13 @@ const applyWriteConcern = require('../utils').applyWriteConcern;
|
|
|
4
4
|
const Code = require('mongodb-core').BSON.Code;
|
|
5
5
|
const resolveReadPreference = require('../utils').resolveReadPreference;
|
|
6
6
|
const crypto = require('crypto');
|
|
7
|
-
const Db = require('../db');
|
|
8
7
|
const debugOptions = require('../utils').debugOptions;
|
|
9
8
|
const handleCallback = require('../utils').handleCallback;
|
|
10
9
|
const MongoError = require('mongodb-core').MongoError;
|
|
11
10
|
const parseIndexOptions = require('../utils').parseIndexOptions;
|
|
12
11
|
const ReadPreference = require('mongodb-core').ReadPreference;
|
|
13
12
|
const toError = require('../utils').toError;
|
|
13
|
+
const CONSTANTS = require('../constants');
|
|
14
14
|
|
|
15
15
|
const count = require('./collection_ops').count;
|
|
16
16
|
const findOne = require('./collection_ops').findOne;
|
|
@@ -64,6 +64,8 @@ const illegalCommandFields = [
|
|
|
64
64
|
* @param {Db~resultCallback} [callback] The command result callback
|
|
65
65
|
*/
|
|
66
66
|
function addUser(db, username, password, options, callback) {
|
|
67
|
+
const Db = require('../db');
|
|
68
|
+
|
|
67
69
|
// Did the user destroy the topology
|
|
68
70
|
if (db.serverConfig && db.serverConfig.isDestroyed())
|
|
69
71
|
return callback(new MongoError('topology was destroyed'));
|
|
@@ -83,7 +85,7 @@ function addUser(db, username, password, options, callback) {
|
|
|
83
85
|
const db = options.dbName ? new Db(options.dbName, db.s.topology, db.s.options) : db;
|
|
84
86
|
|
|
85
87
|
// Fetch a user collection
|
|
86
|
-
const collection = db.collection(
|
|
88
|
+
const collection = db.collection(CONSTANTS.SYSTEM_USER_COLLECTION);
|
|
87
89
|
|
|
88
90
|
// Check if we are inserting the first user
|
|
89
91
|
count(collection, {}, finalOptions, (err, count) => {
|
|
@@ -296,7 +298,7 @@ function createIndex(db, name, fieldOrSpec, options, callback) {
|
|
|
296
298
|
finalOptions.checkKeys = false;
|
|
297
299
|
// Insert document
|
|
298
300
|
db.s.topology.insert(
|
|
299
|
-
`${db.s.databaseName}.${
|
|
301
|
+
`${db.s.databaseName}.${CONSTANTS.SYSTEM_INDEX_COLLECTION}`,
|
|
300
302
|
doc,
|
|
301
303
|
finalOptions,
|
|
302
304
|
(err, result) => {
|
|
@@ -630,6 +632,8 @@ function profilingLevel(db, options, callback) {
|
|
|
630
632
|
* @param {Db~resultCallback} [callback] The command result callback
|
|
631
633
|
*/
|
|
632
634
|
function removeUser(db, username, options, callback) {
|
|
635
|
+
const Db = require('../db');
|
|
636
|
+
|
|
633
637
|
// Attempt to execute command
|
|
634
638
|
executeAuthRemoveUserCommand(db, username, options, (err, result) => {
|
|
635
639
|
if (err && err.code === -5000) {
|
|
@@ -638,7 +642,7 @@ function removeUser(db, username, options, callback) {
|
|
|
638
642
|
const db = options.dbName ? new Db(options.dbName, db.s.topology, db.s.options) : db;
|
|
639
643
|
|
|
640
644
|
// Fetch a user collection
|
|
641
|
-
const collection = db.collection(
|
|
645
|
+
const collection = db.collection(CONSTANTS.SYSTEM_USER_COLLECTION);
|
|
642
646
|
|
|
643
647
|
// Locate the user
|
|
644
648
|
findOne(collection, { user: username }, finalOptions, (err, user) => {
|
|
@@ -555,23 +555,33 @@ function transformUrlOptions(_object) {
|
|
|
555
555
|
object[i] = auth[i];
|
|
556
556
|
}
|
|
557
557
|
}
|
|
558
|
+
|
|
558
559
|
if (auth.username) {
|
|
559
560
|
object.auth = auth;
|
|
560
561
|
object.user = auth.username;
|
|
561
562
|
}
|
|
563
|
+
|
|
562
564
|
if (auth.db) {
|
|
563
|
-
object.
|
|
565
|
+
object.authSource = object.authSource || auth.db;
|
|
564
566
|
}
|
|
565
567
|
}
|
|
568
|
+
|
|
569
|
+
if (_object.defaultDatabase) {
|
|
570
|
+
object.dbName = _object.defaultDatabase;
|
|
571
|
+
}
|
|
572
|
+
|
|
566
573
|
if (object.maxpoolsize) {
|
|
567
574
|
object.poolSize = object.maxpoolsize;
|
|
568
575
|
}
|
|
576
|
+
|
|
569
577
|
if (object.readconcernlevel) {
|
|
570
578
|
object.readConcern = { level: object.readconcernlevel };
|
|
571
579
|
}
|
|
580
|
+
|
|
572
581
|
if (object.wtimeoutms) {
|
|
573
582
|
object.wtimeout = object.wtimeoutms;
|
|
574
583
|
}
|
|
584
|
+
|
|
575
585
|
return object;
|
|
576
586
|
}
|
|
577
587
|
|
package/lib/utils.js
CHANGED
|
@@ -254,7 +254,7 @@ var debugOptions = function(debugFields, options) {
|
|
|
254
254
|
|
|
255
255
|
var decorateCommand = function(command, options, exclude) {
|
|
256
256
|
for (var name in options) {
|
|
257
|
-
if (exclude
|
|
257
|
+
if (exclude.indexOf(name) === -1) command[name] = options[name];
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
return command;
|
|
@@ -588,12 +588,12 @@ function decorateWithCollation(command, target, options) {
|
|
|
588
588
|
throw new TypeError('parameter "target" is missing a topology');
|
|
589
589
|
}
|
|
590
590
|
|
|
591
|
-
// Do we support collation 3.4 and higher
|
|
592
591
|
const capabilities = target.s.topology.capabilities();
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
if (options.collation && typeof options.collation === 'object') {
|
|
592
|
+
if (options.collation && typeof options.collation === 'object') {
|
|
593
|
+
if (capabilities && capabilities.commandsTakeCollation) {
|
|
596
594
|
command.collation = options.collation;
|
|
595
|
+
} else {
|
|
596
|
+
throw new MongoError(`server ${topology.s.coreTopology.name} does not support collation`);
|
|
597
597
|
}
|
|
598
598
|
}
|
|
599
599
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongodb",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.10",
|
|
4
4
|
"description": "The official MongoDB driver for Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"official"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"mongodb-core": "3.1.
|
|
20
|
+
"mongodb-core": "3.1.9",
|
|
21
21
|
"safe-buffer": "^5.1.2"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"standard-version": "^4.4.0",
|
|
44
44
|
"worker-farm": "^1.5.0"
|
|
45
45
|
},
|
|
46
|
-
"author": "Christian Kvalheim",
|
|
47
46
|
"license": "Apache-2.0",
|
|
48
47
|
"engines": {
|
|
49
48
|
"node": ">=4"
|