mongodb 3.6.2 → 3.6.6
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 +74 -1
- package/README.md +63 -69
- package/lib/admin.js +10 -8
- package/lib/aggregation_cursor.js +7 -8
- package/lib/bulk/common.js +5 -4
- package/lib/change_stream.js +1 -1
- package/lib/cmap/connection.js +1 -1
- package/lib/cmap/connection_pool.js +6 -10
- package/lib/collection.js +114 -67
- package/lib/core/auth/gssapi.js +66 -66
- package/lib/core/auth/scram.js +2 -1
- package/lib/core/auth/x509.js +1 -1
- package/lib/core/connection/connect.js +2 -2
- package/lib/core/connection/connection.js +3 -4
- package/lib/core/connection/logger.js +1 -0
- package/lib/core/connection/msg.js +3 -1
- package/lib/core/connection/pool.js +3 -3
- package/lib/core/connection/utils.js +9 -14
- package/lib/core/cursor.js +4 -1
- package/lib/core/index.js +1 -1
- package/lib/core/sdam/monitor.js +22 -14
- package/lib/core/sdam/topology.js +4 -2
- package/lib/core/sdam/topology_description.js +25 -6
- package/lib/core/tools/smoke_plugin.js +1 -0
- package/lib/core/topologies/mongos.js +2 -1
- package/lib/core/topologies/read_preference.js +2 -1
- package/lib/core/topologies/replset.js +14 -8
- package/lib/core/topologies/server.js +5 -4
- package/lib/core/uri_parser.js +11 -3
- package/lib/core/utils.js +2 -5
- package/lib/core/wireprotocol/kill_cursors.js +2 -1
- package/lib/core/wireprotocol/query.js +12 -11
- package/lib/core/wireprotocol/write_command.js +10 -1
- package/lib/cursor.js +15 -13
- package/lib/db.js +52 -30
- package/lib/encrypter.js +163 -0
- package/lib/explain.js +55 -0
- package/lib/gridfs/grid_store.js +14 -9
- package/lib/gridfs-stream/upload.js +6 -3
- package/lib/mongo_client.js +52 -22
- package/lib/operations/add_user.js +5 -2
- package/lib/operations/admin_ops.js +1 -1
- package/lib/operations/aggregate.js +5 -7
- package/lib/operations/command_v2.js +13 -2
- package/lib/operations/common_functions.js +14 -27
- package/lib/operations/connect.js +45 -69
- package/lib/operations/delete_many.js +15 -2
- package/lib/operations/delete_one.js +15 -2
- package/lib/operations/distinct.js +10 -2
- package/lib/operations/execute_operation.js +47 -69
- package/lib/operations/find.js +10 -1
- package/lib/operations/find_and_modify.js +14 -1
- package/lib/operations/find_one.js +4 -0
- package/lib/operations/map_reduce.js +20 -1
- package/lib/operations/operation.js +11 -1
- package/lib/operations/update_many.js +23 -2
- package/lib/operations/update_one.js +22 -16
- package/lib/operations/validate_collection.js +1 -1
- package/lib/topologies/mongos.js +1 -1
- package/lib/topologies/server.js +1 -1
- package/lib/url_parser.js +19 -14
- package/lib/utils.js +115 -32
- package/lib/write_concern.js +22 -4
- package/package.json +31 -15
package/HISTORY.md
CHANGED
|
@@ -1,7 +1,80 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
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
|
+
### [3.6.6](https://github.com/mongodb/node-mongodb-native/compare/v3.6.5...v3.6.6) (2021-04-06)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* always close gridfs upload stream on finish ([#2758](https://github.com/mongodb/node-mongodb-native/issues/2758)) ([c976a01](https://github.com/mongodb/node-mongodb-native/commit/c976a01bf385941bee07fa7f021adf1d425109a8))
|
|
11
|
+
* **csfle:** ensure that monitoring connections are not encrypted ([#2749](https://github.com/mongodb/node-mongodb-native/issues/2749)) ([86bddf1](https://github.com/mongodb/node-mongodb-native/commit/86bddf1ef516d6b8c752082e33c15624753579ab))
|
|
12
|
+
* ensure cursor readPreference is applied to find operations ([#2751](https://github.com/mongodb/node-mongodb-native/issues/2751)) ([91ba19e](https://github.com/mongodb/node-mongodb-native/commit/91ba19efdc4713903584c6161cfdd7b91b0e61f9))
|
|
13
|
+
* ensure monitor has rtt pinger in when calculating rtt ([#2757](https://github.com/mongodb/node-mongodb-native/issues/2757)) ([b94519b](https://github.com/mongodb/node-mongodb-native/commit/b94519ba894b4442d3dabbac59bd12784d8b7178))
|
|
14
|
+
* no infinite loop on windows requiring optional deps ([f2a4ff8](https://github.com/mongodb/node-mongodb-native/commit/f2a4ff870178fbbe8de616c45891368665f29f4b))
|
|
15
|
+
* **NODE-2995:** Add shared metadata MongoClient ([#2760](https://github.com/mongodb/node-mongodb-native/issues/2760)) ([9256242](https://github.com/mongodb/node-mongodb-native/commit/9256242d51c037059c0af5ada9639fc0a74ad033))
|
|
16
|
+
* **NODE-3109:** prevent servername from being IP ([#2763](https://github.com/mongodb/node-mongodb-native/issues/2763)) ([312ffef](https://github.com/mongodb/node-mongodb-native/commit/312ffef18c66a0020f19bdc1d654987d9148d709))
|
|
17
|
+
|
|
18
|
+
### [3.6.5](https://github.com/mongodb/node-mongodb-native/compare/v3.6.4...v3.6.5) (2021-03-16)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* MongoError circular dependency warning ([#2734](https://github.com/mongodb/node-mongodb-native/issues/2734)) ([d67ffa7](https://github.com/mongodb/node-mongodb-native/commit/d67ffa7a2e3f86734c7e9b6944aab1d765b9e75e))
|
|
24
|
+
* move session support check to operation layer ([#2739](https://github.com/mongodb/node-mongodb-native/issues/2739)) ([8b370a7](https://github.com/mongodb/node-mongodb-native/commit/8b370a7ad784f5759c964cdfaec62e06c896dc95))
|
|
25
|
+
* session support detection spec compliance ([#2732](https://github.com/mongodb/node-mongodb-native/issues/2732)) ([9baec71](https://github.com/mongodb/node-mongodb-native/commit/9baec7128f612f2d9c290c85d24e33602f911499))
|
|
26
|
+
* use emitWarning API for internal messages ([#2743](https://github.com/mongodb/node-mongodb-native/issues/2743)) ([8bd9777](https://github.com/mongodb/node-mongodb-native/commit/8bd9777b0aedd56b81675c3e79fae63432319982))
|
|
27
|
+
|
|
28
|
+
### [3.6.4](https://github.com/mongodb/node-mongodb-native/compare/v3.6.3...v3.6.4) (2021-02-02)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Features
|
|
32
|
+
|
|
33
|
+
* add explain support ([#2626](https://github.com/mongodb/node-mongodb-native/issues/2626)) ([a827807](https://github.com/mongodb/node-mongodb-native/commit/a8278070992d2de4134dc0841b4027a6cc745a93))
|
|
34
|
+
* Deprecate top-level write concern option keys ([#2624](https://github.com/mongodb/node-mongodb-native/issues/2624)) ([0516d93](https://github.com/mongodb/node-mongodb-native/commit/0516d93f74de4b58a99e8455e59678d4b09cd4a7))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Bug Fixes
|
|
38
|
+
|
|
39
|
+
* Allow GridFS write stream to destroy ([#2702](https://github.com/mongodb/node-mongodb-native/issues/2702)) ([b5e9d67](https://github.com/mongodb/node-mongodb-native/commit/b5e9d67d5cd9b1912a349789cf2a122e00a46d1b))
|
|
40
|
+
* awaitable isMaster timeout must respect connectTimeoutMS ([#2627](https://github.com/mongodb/node-mongodb-native/issues/2627)) ([b365c50](https://github.com/mongodb/node-mongodb-native/commit/b365c5061ded832e1682167edac58e8a04b05fc4))
|
|
41
|
+
* don't add empty query string items to connection string ([8897259](https://github.com/mongodb/node-mongodb-native/commit/889725980ec1e3b4be4a74170bea0a3e3d23cf13))
|
|
42
|
+
* don't reset monitor if we aren't streaming topology changes ([a10171b](https://github.com/mongodb/node-mongodb-native/commit/a10171b57d2414f6df2aa8ffe9c2d3938ad838d1))
|
|
43
|
+
* dont parse tls/ssl file paths in uri ([#2718](https://github.com/mongodb/node-mongodb-native/issues/2718)) ([f89e4c1](https://github.com/mongodb/node-mongodb-native/commit/f89e4c1bd59c64664e8c9aa218bcb856be325d34))
|
|
44
|
+
* hasAtomicOperator check respects toBSON transformation ([#2696](https://github.com/mongodb/node-mongodb-native/issues/2696)) ([60936dc](https://github.com/mongodb/node-mongodb-native/commit/60936dca74167de239d1bb51a23cc9870860bdc4))
|
|
45
|
+
* honor ignoreUndefined on findAndModify commands ([#2671](https://github.com/mongodb/node-mongodb-native/issues/2671)) ([a25b67c](https://github.com/mongodb/node-mongodb-native/commit/a25b67c6ac13b6347cb78c4fc56613f3daf44300))
|
|
46
|
+
* ignore ENOTFOUND during TXT record lookup ([2036fe7](https://github.com/mongodb/node-mongodb-native/commit/2036fe7b298b9678e29ede87c1035c748ff89fcd))
|
|
47
|
+
* respect readPreference and writeConcern from connection string ([#2711](https://github.com/mongodb/node-mongodb-native/issues/2711)) ([b657c8c](https://github.com/mongodb/node-mongodb-native/commit/b657c8c4f3f86018cc4824f84cb22e1527d9f9af))
|
|
48
|
+
* restore auto direct connection behavior ([#2719](https://github.com/mongodb/node-mongodb-native/issues/2719)) ([617d9de](https://github.com/mongodb/node-mongodb-native/commit/617d9dec5180c5f7b67bd8c944c168d4cbd27e1c))
|
|
49
|
+
* support empty TXT records in legacy url parser ([2fa5c5f](https://github.com/mongodb/node-mongodb-native/commit/2fa5c5f2a113920baa8e67a1c0d65432690d37fc))
|
|
50
|
+
* transition topology state before async calls ([#2637](https://github.com/mongodb/node-mongodb-native/issues/2637)) ([9df093c](https://github.com/mongodb/node-mongodb-native/commit/9df093c1d46e1f8616c7a979324923205ac3dcd2))
|
|
51
|
+
* **cursor:** don't use other operation's session for cloned cursor operation ([#2705](https://github.com/mongodb/node-mongodb-native/issues/2705)) ([8082c89](https://github.com/mongodb/node-mongodb-native/commit/8082c89f8ef3624d22f4bdd6066b6f72c44f763d))
|
|
52
|
+
* **find:** correctly translate timeout option into noCursorTimeout ([#2700](https://github.com/mongodb/node-mongodb-native/issues/2700)) ([e257e6b](https://github.com/mongodb/node-mongodb-native/commit/e257e6b19d810920bafc579e725e09bd0607b74b))
|
|
53
|
+
|
|
54
|
+
<a name="3.6.3"></a>
|
|
55
|
+
## [3.6.3](https://github.com/mongodb/node-mongodb-native/compare/v3.6.1...v3.6.3) (2020-11-06)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
### Bug Fixes
|
|
59
|
+
|
|
60
|
+
* add peerDependenciesMeta to mark optional deps ([#2606](https://github.com/mongodb/node-mongodb-native/issues/2606)) ([186090e](https://github.com/mongodb/node-mongodb-native/commit/186090e))
|
|
61
|
+
* adds topology discovery for sharded cluster ([f8fd310](https://github.com/mongodb/node-mongodb-native/commit/f8fd310))
|
|
62
|
+
* allow event loop to process during wait queue processing ([#2537](https://github.com/mongodb/node-mongodb-native/issues/2537)) ([4e03dfa](https://github.com/mongodb/node-mongodb-native/commit/4e03dfa))
|
|
63
|
+
* Change socket timeout default to 0 ([#2572](https://github.com/mongodb/node-mongodb-native/issues/2572)) ([89b77ed](https://github.com/mongodb/node-mongodb-native/commit/89b77ed))
|
|
64
|
+
* connection leak if wait queue member cancelled ([cafaa1b](https://github.com/mongodb/node-mongodb-native/commit/cafaa1b))
|
|
65
|
+
* correctly assign username to X509 auth command ([#2587](https://github.com/mongodb/node-mongodb-native/issues/2587)) ([9110a45](https://github.com/mongodb/node-mongodb-native/commit/9110a45))
|
|
66
|
+
* correctly re-establishes pipe destinations ([a6e7caf](https://github.com/mongodb/node-mongodb-native/commit/a6e7caf))
|
|
67
|
+
* Fix test filters and revert mocha version ([#2558](https://github.com/mongodb/node-mongodb-native/issues/2558)) ([0e5c45a](https://github.com/mongodb/node-mongodb-native/commit/0e5c45a))
|
|
68
|
+
* move kerberos client setup from prepare to auth ([#2608](https://github.com/mongodb/node-mongodb-native/issues/2608)) ([033b6e7](https://github.com/mongodb/node-mongodb-native/commit/033b6e7))
|
|
69
|
+
* permit waking async interval with unreliable clock ([e0e11bb](https://github.com/mongodb/node-mongodb-native/commit/e0e11bb))
|
|
70
|
+
* remove geoNear deprecation ([4955a52](https://github.com/mongodb/node-mongodb-native/commit/4955a52))
|
|
71
|
+
* revert use of setImmediate to process.nextTick ([#2611](https://github.com/mongodb/node-mongodb-native/issues/2611)) ([c9f9d5e](https://github.com/mongodb/node-mongodb-native/commit/c9f9d5e))
|
|
72
|
+
* sets primary read preference for writes ([ddcd03d](https://github.com/mongodb/node-mongodb-native/commit/ddcd03d))
|
|
73
|
+
* use options for readPreference in client ([6acced0](https://github.com/mongodb/node-mongodb-native/commit/6acced0))
|
|
74
|
+
* user roles take single string & DDL readPreference tests ([967de13](https://github.com/mongodb/node-mongodb-native/commit/967de13))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
5
78
|
<a name="3.6.2"></a>
|
|
6
79
|
## [3.6.2](https://github.com/mongodb/node-mongodb-native/compare/v3.6.1...v3.6.2) (2020-09-10)
|
|
7
80
|
|
package/README.md
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
# MongoDB NodeJS Driver
|
|
2
2
|
|
|
3
|
-
[](https://coveralls.io/github/mongodb/node-mongodb-native?branch=2.1)
|
|
5
|
-
[](https://gitter.im/mongodb/node-mongodb-native?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
|
3
|
+
[](https://nodei.co/npm/mongodb/)
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
The official [MongoDB](https://www.mongodb.com/) driver for Node.js.
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
**NOTE: v3.x released with breaking API changes. You can find a list of changes [here](CHANGES_3.0.0.md).**
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
## Version 4.0
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
**Looking for the latest?** We're working on the next major version of the driver, now in beta.
|
|
12
|
+
Check out our [beta version 4.0 here](https://github.com/mongodb/node-mongodb-native/tree/4.0), which includes a full migration of the driver to TypeScript.
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
|
18
|
-
|
|
|
19
|
-
|
|
|
20
|
-
|
|
|
14
|
+
## Quick Links
|
|
15
|
+
|
|
16
|
+
| what | where |
|
|
17
|
+
| ------------- | ---------------------------------------------------- |
|
|
18
|
+
| documentation | http://mongodb.github.io/node-mongodb-native |
|
|
19
|
+
| api-doc | http://mongodb.github.io/node-mongodb-native/3.6/api |
|
|
20
|
+
| source | https://github.com/mongodb/node-mongodb-native |
|
|
21
|
+
| mongodb | http://www.mongodb.org |
|
|
21
22
|
|
|
22
23
|
### Bugs / Feature Requests
|
|
23
24
|
|
|
@@ -43,12 +44,12 @@ Change history can be found in [`HISTORY.md`](HISTORY.md).
|
|
|
43
44
|
|
|
44
45
|
For version compatibility matrices, please refer to the following links:
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
- [MongoDB](https://docs.mongodb.com/ecosystem/drivers/driver-compatibility-reference/#reference-compatibility-mongodb-node)
|
|
48
|
+
- [NodeJS](https://docs.mongodb.com/ecosystem/drivers/driver-compatibility-reference/#reference-compatibility-language-node)
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
## Installation
|
|
50
51
|
|
|
51
|
-
The recommended way to get started using the Node.js
|
|
52
|
+
The recommended way to get started using the Node.js driver is by using `npm` (Node Package Manager) to install the dependency in your project.
|
|
52
53
|
|
|
53
54
|
## MongoDB Driver
|
|
54
55
|
|
|
@@ -66,10 +67,10 @@ You can also use the [Yarn](https://yarnpkg.com/en) package manager.
|
|
|
66
67
|
|
|
67
68
|
The MongoDB driver depends on several other packages. These are:
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
- [bson](https://github.com/mongodb/js-bson)
|
|
71
|
+
- [bson-ext](https://github.com/mongodb-js/bson-ext)
|
|
72
|
+
- [kerberos](https://github.com/mongodb-js/kerberos)
|
|
73
|
+
- [mongodb-client-encryption](https://github.com/mongodb/libmongocrypt#readme)
|
|
73
74
|
|
|
74
75
|
The `kerberos` package is a C++ extension that requires a build environment to be installed on your system. You must be able to build Node.js itself in order to compile and install the `kerberos` module. Furthermore, the `kerberos` module requires the MIT Kerberos package to correctly compile on UNIX operating systems. Consult your UNIX operation system package manager for what libraries to install.
|
|
75
76
|
|
|
@@ -110,9 +111,9 @@ This will print out all the steps npm is performing while trying to install the
|
|
|
110
111
|
|
|
111
112
|
A compiler tool chain known to work for compiling `kerberos` on Windows is the following.
|
|
112
113
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
- Visual Studio C++ 2010 (do not use higher versions)
|
|
115
|
+
- Windows 7 64bit SDK
|
|
116
|
+
- Python 2.7 or higher
|
|
116
117
|
|
|
117
118
|
Open the Visual Studio command prompt. Ensure `node.exe` is in your path and install `node-gyp`.
|
|
118
119
|
|
|
@@ -170,7 +171,7 @@ For complete MongoDB installation instructions, see [the manual](https://docs.mo
|
|
|
170
171
|
|
|
171
172
|
1. Download the right MongoDB version from [MongoDB](https://www.mongodb.org/downloads)
|
|
172
173
|
2. Create a database directory (in this case under **/data**).
|
|
173
|
-
3. Install and start a
|
|
174
|
+
3. Install and start a `mongod` process.
|
|
174
175
|
|
|
175
176
|
```bash
|
|
176
177
|
mongod --dbpath=/data
|
|
@@ -194,11 +195,11 @@ const url = 'mongodb://localhost:27017';
|
|
|
194
195
|
|
|
195
196
|
// Database Name
|
|
196
197
|
const dbName = 'myproject';
|
|
197
|
-
|
|
198
|
+
const client = new MongoClient(url);
|
|
198
199
|
// Use connect method to connect to the server
|
|
199
|
-
|
|
200
|
+
client.connect(function(err) {
|
|
200
201
|
assert.equal(null, err);
|
|
201
|
-
console.log(
|
|
202
|
+
console.log('Connected successfully to server');
|
|
202
203
|
|
|
203
204
|
const db = client.db(dbName);
|
|
204
205
|
|
|
@@ -224,23 +225,21 @@ const insertDocuments = function(db, callback) {
|
|
|
224
225
|
// Get the documents collection
|
|
225
226
|
const collection = db.collection('documents');
|
|
226
227
|
// Insert some documents
|
|
227
|
-
collection.insertMany([
|
|
228
|
-
{a : 1}, {a : 2}, {a : 3}
|
|
229
|
-
], function(err, result) {
|
|
228
|
+
collection.insertMany([{ a: 1 }, { a: 2 }, { a: 3 }], function(err, result) {
|
|
230
229
|
assert.equal(err, null);
|
|
231
230
|
assert.equal(3, result.result.n);
|
|
232
231
|
assert.equal(3, result.ops.length);
|
|
233
|
-
console.log(
|
|
232
|
+
console.log('Inserted 3 documents into the collection');
|
|
234
233
|
callback(result);
|
|
235
234
|
});
|
|
236
|
-
}
|
|
235
|
+
};
|
|
237
236
|
```
|
|
238
237
|
|
|
239
238
|
The **insert** command returns an object with the following fields:
|
|
240
239
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
240
|
+
- **result** Contains the result document from MongoDB
|
|
241
|
+
- **ops** Contains the documents inserted with added **\_id** fields
|
|
242
|
+
- **connection** Contains the connection used to perform the insert
|
|
244
243
|
|
|
245
244
|
Add the following code to call the **insertDocuments** function:
|
|
246
245
|
|
|
@@ -257,7 +256,7 @@ const dbName = 'myproject';
|
|
|
257
256
|
// Use connect method to connect to the server
|
|
258
257
|
MongoClient.connect(url, function(err, client) {
|
|
259
258
|
assert.equal(null, err);
|
|
260
|
-
console.log(
|
|
259
|
+
console.log('Connected successfully to server');
|
|
261
260
|
|
|
262
261
|
const db = client.db(dbName);
|
|
263
262
|
|
|
@@ -291,11 +290,11 @@ const findDocuments = function(db, callback) {
|
|
|
291
290
|
// Find some documents
|
|
292
291
|
collection.find({}).toArray(function(err, docs) {
|
|
293
292
|
assert.equal(err, null);
|
|
294
|
-
console.log(
|
|
295
|
-
console.log(docs)
|
|
293
|
+
console.log('Found the following records');
|
|
294
|
+
console.log(docs);
|
|
296
295
|
callback(docs);
|
|
297
296
|
});
|
|
298
|
-
}
|
|
297
|
+
};
|
|
299
298
|
```
|
|
300
299
|
|
|
301
300
|
This query returns all the documents in the **documents** collection. Add the **findDocument** method to the **MongoClient.connect** callback:
|
|
@@ -313,7 +312,7 @@ const dbName = 'myproject';
|
|
|
313
312
|
// Use connect method to connect to the server
|
|
314
313
|
MongoClient.connect(url, function(err, client) {
|
|
315
314
|
assert.equal(null, err);
|
|
316
|
-
console.log(
|
|
315
|
+
console.log('Connected correctly to server');
|
|
317
316
|
|
|
318
317
|
const db = client.db(dbName);
|
|
319
318
|
|
|
@@ -334,16 +333,16 @@ const findDocuments = function(db, callback) {
|
|
|
334
333
|
// Get the documents collection
|
|
335
334
|
const collection = db.collection('documents');
|
|
336
335
|
// Find some documents
|
|
337
|
-
collection.find({
|
|
336
|
+
collection.find({ a: 3 }).toArray(function(err, docs) {
|
|
338
337
|
assert.equal(err, null);
|
|
339
|
-
console.log(
|
|
338
|
+
console.log('Found the following records');
|
|
340
339
|
console.log(docs);
|
|
341
340
|
callback(docs);
|
|
342
341
|
});
|
|
343
|
-
}
|
|
342
|
+
};
|
|
344
343
|
```
|
|
345
344
|
|
|
346
|
-
Only the documents which match
|
|
345
|
+
Only the documents which match `'a' : 3` should be returned.
|
|
347
346
|
|
|
348
347
|
### Update a document
|
|
349
348
|
|
|
@@ -354,14 +353,13 @@ const updateDocument = function(db, callback) {
|
|
|
354
353
|
// Get the documents collection
|
|
355
354
|
const collection = db.collection('documents');
|
|
356
355
|
// Update document where a is 2, set b equal to 1
|
|
357
|
-
collection.updateOne({ a
|
|
358
|
-
, { $set: { b : 1 } }, function(err, result) {
|
|
356
|
+
collection.updateOne({ a: 2 }, { $set: { b: 1 } }, function(err, result) {
|
|
359
357
|
assert.equal(err, null);
|
|
360
358
|
assert.equal(1, result.result.n);
|
|
361
|
-
console.log(
|
|
359
|
+
console.log('Updated the document with the field a equal to 2');
|
|
362
360
|
callback(result);
|
|
363
361
|
});
|
|
364
|
-
}
|
|
362
|
+
};
|
|
365
363
|
```
|
|
366
364
|
|
|
367
365
|
The method updates the first document where the field **a** is equal to **2** by adding a new field **b** to the document set to **1**. Next, update the callback function from **MongoClient.connect** to include the update method.
|
|
@@ -379,7 +377,7 @@ const dbName = 'myproject';
|
|
|
379
377
|
// Use connect method to connect to the server
|
|
380
378
|
MongoClient.connect(url, function(err, client) {
|
|
381
379
|
assert.equal(null, err);
|
|
382
|
-
console.log(
|
|
380
|
+
console.log('Connected successfully to server');
|
|
383
381
|
|
|
384
382
|
const db = client.db(dbName);
|
|
385
383
|
|
|
@@ -400,13 +398,13 @@ const removeDocument = function(db, callback) {
|
|
|
400
398
|
// Get the documents collection
|
|
401
399
|
const collection = db.collection('documents');
|
|
402
400
|
// Delete document where a is 3
|
|
403
|
-
collection.deleteOne({ a
|
|
401
|
+
collection.deleteOne({ a: 3 }, function(err, result) {
|
|
404
402
|
assert.equal(err, null);
|
|
405
403
|
assert.equal(1, result.result.n);
|
|
406
|
-
console.log(
|
|
404
|
+
console.log('Removed the document with the field a equal to 3');
|
|
407
405
|
callback(result);
|
|
408
406
|
});
|
|
409
|
-
}
|
|
407
|
+
};
|
|
410
408
|
```
|
|
411
409
|
|
|
412
410
|
Add the new method to the **MongoClient.connect** callback function.
|
|
@@ -424,7 +422,7 @@ const dbName = 'myproject';
|
|
|
424
422
|
// Use connect method to connect to the server
|
|
425
423
|
MongoClient.connect(url, function(err, client) {
|
|
426
424
|
assert.equal(null, err);
|
|
427
|
-
console.log(
|
|
425
|
+
console.log('Connected successfully to server');
|
|
428
426
|
|
|
429
427
|
const db = client.db(dbName);
|
|
430
428
|
|
|
@@ -446,18 +444,14 @@ performance. The following function creates an index on the **a** field in the
|
|
|
446
444
|
|
|
447
445
|
```js
|
|
448
446
|
const indexCollection = function(db, callback) {
|
|
449
|
-
db.collection('documents').createIndex(
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
console.log(results);
|
|
454
|
-
callback();
|
|
455
|
-
}
|
|
456
|
-
);
|
|
447
|
+
db.collection('documents').createIndex({ a: 1 }, null, function(err, results) {
|
|
448
|
+
console.log(results);
|
|
449
|
+
callback();
|
|
450
|
+
});
|
|
457
451
|
};
|
|
458
452
|
```
|
|
459
453
|
|
|
460
|
-
Add the
|
|
454
|
+
Add the `indexCollection` method to your app:
|
|
461
455
|
|
|
462
456
|
```js
|
|
463
457
|
const MongoClient = require('mongodb').MongoClient;
|
|
@@ -471,7 +465,7 @@ const dbName = 'myproject';
|
|
|
471
465
|
// Use connect method to connect to the server
|
|
472
466
|
MongoClient.connect(url, function(err, client) {
|
|
473
467
|
assert.equal(null, err);
|
|
474
|
-
console.log(
|
|
468
|
+
console.log('Connected successfully to server');
|
|
475
469
|
|
|
476
470
|
const db = client.db(dbName);
|
|
477
471
|
|
|
@@ -487,13 +481,13 @@ For more detailed information, see the [tutorials](docs/reference/content/tutori
|
|
|
487
481
|
|
|
488
482
|
## Next Steps
|
|
489
483
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
484
|
+
- [MongoDB Documentation](http://mongodb.org)
|
|
485
|
+
- [Read about Schemas](http://learnmongodbthehardway.com)
|
|
486
|
+
- [Star us on GitHub](https://github.com/mongodb/node-mongodb-native)
|
|
493
487
|
|
|
494
488
|
## License
|
|
495
489
|
|
|
496
490
|
[Apache 2.0](LICENSE.md)
|
|
497
491
|
|
|
498
|
-
© 2009-2012 Christian Amor Kvalheim
|
|
492
|
+
© 2009-2012 Christian Amor Kvalheim
|
|
499
493
|
© 2012-present MongoDB [Contributors](CONTRIBUTORS.md)
|
package/lib/admin.js
CHANGED
|
@@ -166,10 +166,11 @@ Admin.prototype.ping = function(options, callback) {
|
|
|
166
166
|
* @param {string} username The username.
|
|
167
167
|
* @param {string} password The password.
|
|
168
168
|
* @param {object} [options] Optional settings.
|
|
169
|
-
* @param {(number|string)} [options.w] The write concern.
|
|
170
|
-
* @param {number} [options.wtimeout] The write concern timeout.
|
|
171
|
-
* @param {boolean} [options.j=false] Specify a journal write concern.
|
|
172
|
-
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
|
|
169
|
+
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
|
170
|
+
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
|
171
|
+
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
|
172
|
+
* @param {boolean} [options.fsync=false] **Deprecated** Specify a file sync write concern. Use writeConcern instead.
|
|
173
|
+
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
|
173
174
|
* @param {object} [options.customData] Custom data associated with the user (only Mongodb 2.6 or higher)
|
|
174
175
|
* @param {object[]} [options.roles] Roles associated with the created user (only Mongodb 2.6 or higher)
|
|
175
176
|
* @param {ClientSession} [options.session] optional session to use for this operation
|
|
@@ -203,10 +204,11 @@ Admin.prototype.addUser = function(username, password, options, callback) {
|
|
|
203
204
|
* @method
|
|
204
205
|
* @param {string} username The username.
|
|
205
206
|
* @param {object} [options] Optional settings.
|
|
206
|
-
* @param {(number|string)} [options.w] The write concern.
|
|
207
|
-
* @param {number} [options.wtimeout] The write concern timeout.
|
|
208
|
-
* @param {boolean} [options.j=false] Specify a journal write concern.
|
|
209
|
-
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
|
|
207
|
+
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
|
208
|
+
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
|
209
|
+
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
|
210
|
+
* @param {boolean} [options.fsync=false] **Deprecated** Specify a file sync write concern. Use writeConcern instead.
|
|
211
|
+
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
|
210
212
|
* @param {ClientSession} [options.session] optional session to use for this operation
|
|
211
213
|
* @param {Admin~resultCallback} [callback] The command result callback
|
|
212
214
|
* @return {Promise} returns Promise if no callback passed
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
const MongoError = require('./core').MongoError;
|
|
4
4
|
const Cursor = require('./cursor');
|
|
5
5
|
const CursorState = require('./core/cursor').CursorState;
|
|
6
|
-
const deprecate = require('util').deprecate;
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* @fileOverview The **AggregationCursor** class is an internal class that embodies an aggregation cursor on MongoDB
|
|
@@ -203,7 +202,7 @@ class AggregationCursor extends Cursor {
|
|
|
203
202
|
/**
|
|
204
203
|
* Add a unwind stage to the aggregation pipeline
|
|
205
204
|
* @method
|
|
206
|
-
* @param {
|
|
205
|
+
* @param {(string|object)} field The unwind field name or stage document.
|
|
207
206
|
* @return {AggregationCursor}
|
|
208
207
|
*/
|
|
209
208
|
unwind(field) {
|
|
@@ -225,12 +224,6 @@ class AggregationCursor extends Cursor {
|
|
|
225
224
|
// aliases
|
|
226
225
|
AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
|
|
227
226
|
|
|
228
|
-
// deprecated methods
|
|
229
|
-
deprecate(
|
|
230
|
-
AggregationCursor.prototype.geoNear,
|
|
231
|
-
'The `$geoNear` stage is deprecated in MongoDB 4.0, and removed in version 4.2.'
|
|
232
|
-
);
|
|
233
|
-
|
|
234
227
|
/**
|
|
235
228
|
* AggregationCursor stream data event, fired for each document in the cursor.
|
|
236
229
|
*
|
|
@@ -329,7 +322,13 @@ deprecate(
|
|
|
329
322
|
|
|
330
323
|
/**
|
|
331
324
|
* Execute the explain for the cursor
|
|
325
|
+
*
|
|
326
|
+
* For backwards compatibility, a verbosity of true is interpreted as "allPlansExecution"
|
|
327
|
+
* and false as "queryPlanner". Prior to server version 3.6, aggregate()
|
|
328
|
+
* ignores the verbosity parameter and executes in "queryPlanner".
|
|
329
|
+
*
|
|
332
330
|
* @method AggregationCursor.prototype.explain
|
|
331
|
+
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [verbosity=true] - An optional mode in which to run the explain.
|
|
333
332
|
* @param {AggregationCursor~resultCallback} [callback] The result callback.
|
|
334
333
|
* @return {Promise} returns Promise if no callback passed
|
|
335
334
|
*/
|
package/lib/bulk/common.js
CHANGED
|
@@ -1125,10 +1125,11 @@ class BulkOperationBase {
|
|
|
1125
1125
|
* @method
|
|
1126
1126
|
* @param {WriteConcern} [_writeConcern] Optional write concern. Can also be specified through options.
|
|
1127
1127
|
* @param {object} [options] Optional settings.
|
|
1128
|
-
* @param {(number|string)} [options.w] The write concern.
|
|
1129
|
-
* @param {number} [options.wtimeout] The write concern timeout.
|
|
1130
|
-
* @param {boolean} [options.j=false] Specify a journal write concern.
|
|
1131
|
-
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
|
|
1128
|
+
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
|
1129
|
+
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
|
1130
|
+
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
|
1131
|
+
* @param {boolean} [options.fsync=false] **Deprecated** Specify a file sync write concern. Use writeConcern instead.
|
|
1132
|
+
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
|
1132
1133
|
* @param {BulkOperationBase~resultCallback} [callback] A callback that will be invoked when bulkWrite finishes/errors
|
|
1133
1134
|
* @throws {MongoError} Throws error if the bulk object has already been executed
|
|
1134
1135
|
* @throws {MongoError} Throws error if the bulk object does not have any operations
|
package/lib/change_stream.js
CHANGED
|
@@ -437,7 +437,7 @@ function createChangeStreamCursor(self, options) {
|
|
|
437
437
|
|
|
438
438
|
if (self.pipeDestinations) {
|
|
439
439
|
const cursorStream = changeStreamCursor.stream(self.streamOptions);
|
|
440
|
-
for (let pipeDestination
|
|
440
|
+
for (let pipeDestination of self.pipeDestinations) {
|
|
441
441
|
cursorStream.pipe(pipeDestination);
|
|
442
442
|
}
|
|
443
443
|
}
|
package/lib/cmap/connection.js
CHANGED
|
@@ -32,7 +32,7 @@ class Connection extends EventEmitter {
|
|
|
32
32
|
this.id = options.id;
|
|
33
33
|
this.address = streamIdentifier(stream);
|
|
34
34
|
this.bson = options.bson;
|
|
35
|
-
this.socketTimeout = typeof options.socketTimeout === 'number' ? options.socketTimeout :
|
|
35
|
+
this.socketTimeout = typeof options.socketTimeout === 'number' ? options.socketTimeout : 0;
|
|
36
36
|
this.host = options.host || 'localhost';
|
|
37
37
|
this.port = options.port || 27017;
|
|
38
38
|
this.monitorCommands =
|
|
@@ -95,7 +95,7 @@ const VALID_POOL_OPTIONS = new Set([
|
|
|
95
95
|
|
|
96
96
|
function resolveOptions(options, defaults) {
|
|
97
97
|
const newOptions = Array.from(VALID_POOL_OPTIONS).reduce((obj, key) => {
|
|
98
|
-
if (
|
|
98
|
+
if (Object.prototype.hasOwnProperty.call(options, key)) {
|
|
99
99
|
obj[key] = options[key];
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -233,7 +233,7 @@ class ConnectionPool extends EventEmitter {
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
this[kWaitQueue].push(waitQueueMember);
|
|
236
|
-
|
|
236
|
+
process.nextTick(() => processWaitQueue(this));
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
/**
|
|
@@ -258,7 +258,7 @@ class ConnectionPool extends EventEmitter {
|
|
|
258
258
|
destroyConnection(this, connection, reason);
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
|
|
261
|
+
process.nextTick(() => processWaitQueue(this));
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
/**
|
|
@@ -428,7 +428,7 @@ function createConnection(pool, callback) {
|
|
|
428
428
|
|
|
429
429
|
// otherwise add it to the pool for later acquisition, and try to process the wait queue
|
|
430
430
|
pool[kConnections].push(connection);
|
|
431
|
-
|
|
431
|
+
process.nextTick(() => processWaitQueue(pool));
|
|
432
432
|
});
|
|
433
433
|
}
|
|
434
434
|
|
|
@@ -439,7 +439,7 @@ function destroyConnection(pool, connection, reason) {
|
|
|
439
439
|
pool[kPermits]++;
|
|
440
440
|
|
|
441
441
|
// destroy the connection
|
|
442
|
-
|
|
442
|
+
process.nextTick(() => connection.destroy());
|
|
443
443
|
}
|
|
444
444
|
|
|
445
445
|
function processWaitQueue(pool) {
|
|
@@ -477,7 +477,7 @@ function processWaitQueue(pool) {
|
|
|
477
477
|
if (pool.waitQueueSize && (maxPoolSize <= 0 || pool.totalConnectionCount < maxPoolSize)) {
|
|
478
478
|
createConnection(pool, (err, connection) => {
|
|
479
479
|
const waitQueueMember = pool[kWaitQueue].shift();
|
|
480
|
-
if (waitQueueMember == null) {
|
|
480
|
+
if (waitQueueMember == null || waitQueueMember[kCancelled]) {
|
|
481
481
|
if (err == null) {
|
|
482
482
|
pool[kConnections].push(connection);
|
|
483
483
|
}
|
|
@@ -485,10 +485,6 @@ function processWaitQueue(pool) {
|
|
|
485
485
|
return;
|
|
486
486
|
}
|
|
487
487
|
|
|
488
|
-
if (waitQueueMember[kCancelled]) {
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
488
|
if (err) {
|
|
493
489
|
pool.emit('connectionCheckOutFailed', new ConnectionCheckOutFailedEvent(pool, err));
|
|
494
490
|
} else {
|