mongodb 3.6.8 → 3.6.9

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 CHANGED
@@ -2,6 +2,14 @@
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.9](https://github.com/mongodb/node-mongodb-native/compare/v3.6.8...v3.6.9) (2021-05-26)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **NODE-3309:** remove redundant iteration of bulk write result ([#2815](https://github.com/mongodb/node-mongodb-native/issues/2815)) ([fac9610](https://github.com/mongodb/node-mongodb-native/commit/fac961086eafa0f7437576fd6af900e1f9fe22ed))
11
+ * fix url parsing for a mongodb+srv url that has commas in the database name ([#2789](https://github.com/mongodb/node-mongodb-native/issues/2789)) ([58c4e69](https://github.com/mongodb/node-mongodb-native/commit/58c4e693cc3a717254144d5f9bdddd8414217e97))
12
+
5
13
  ### [3.6.8](https://github.com/mongodb/node-mongodb-native/compare/v3.6.7...v3.6.8) (2021-05-21)
6
14
 
7
15
 
@@ -57,6 +57,9 @@ class Batch {
57
57
  }
58
58
  }
59
59
 
60
+ const kUpsertedIds = Symbol('upsertedIds');
61
+ const kInsertedIds = Symbol('insertedIds');
62
+
60
63
  /**
61
64
  * @classdesc
62
65
  * The result of a bulk write.
@@ -69,6 +72,8 @@ class BulkWriteResult {
69
72
  */
70
73
  constructor(bulkResult) {
71
74
  this.result = bulkResult;
75
+ this[kUpsertedIds] = undefined;
76
+ this[kInsertedIds] = undefined;
72
77
  }
73
78
 
74
79
  /** Number of documents inserted. */
@@ -94,20 +99,33 @@ class BulkWriteResult {
94
99
 
95
100
  /** Upserted document generated Id's, hash key is the index of the originating operation */
96
101
  get upsertedIds() {
97
- const upserted = {};
98
- for (const doc of !this.result.upserted ? [] : this.result.upserted) {
99
- upserted[doc.index] = doc._id;
102
+ if (this[kUpsertedIds]) {
103
+ return this[kUpsertedIds];
104
+ }
105
+
106
+ this[kUpsertedIds] = {};
107
+ for (const doc of this.result.upserted || []) {
108
+ this[kUpsertedIds][doc.index] = doc._id;
100
109
  }
101
- return upserted;
110
+ return this[kUpsertedIds];
102
111
  }
103
112
 
104
113
  /** Inserted document generated Id's, hash key is the index of the originating operation */
105
114
  get insertedIds() {
106
- const inserted = {};
107
- for (const doc of !this.result.insertedIds ? [] : this.result.insertedIds) {
108
- inserted[doc.index] = doc._id;
115
+ if (this[kInsertedIds]) {
116
+ return this[kInsertedIds];
117
+ }
118
+
119
+ this[kInsertedIds] = {};
120
+ for (const doc of this.result.insertedIds || []) {
121
+ this[kInsertedIds][doc.index] = doc._id;
109
122
  }
110
- return inserted;
123
+ return this[kInsertedIds];
124
+ }
125
+
126
+ /** The number of inserted documents @type {number} */
127
+ get n() {
128
+ return this.result.insertedCount;
111
129
  }
112
130
 
113
131
  /**
@@ -1370,5 +1388,6 @@ module.exports = {
1370
1388
  INSERT: INSERT,
1371
1389
  UPDATE: UPDATE,
1372
1390
  REMOVE: REMOVE,
1373
- BulkWriteError
1391
+ BulkWriteError,
1392
+ BulkWriteResult
1374
1393
  };
@@ -52,7 +52,9 @@ function parseSrvConnectionString(uri, options, callback) {
52
52
  }
53
53
 
54
54
  result.domainLength = result.hostname.split('.').length;
55
- if (result.pathname && result.pathname.match(',')) {
55
+
56
+ const hostname = uri.substring('mongodb+srv://'.length).split('/')[0];
57
+ if (hostname.match(',')) {
56
58
  return callback(new MongoParseError('Invalid URI, cannot contain multiple hostnames'));
57
59
  }
58
60
 
@@ -70,23 +70,6 @@ class BulkWriteOperation extends OperationBase {
70
70
  return callback(err, null);
71
71
  }
72
72
 
73
- // Update the n
74
- r.n = r.insertedCount;
75
-
76
- // Inserted documents
77
- const inserted = r.getInsertedIds();
78
- // Map inserted ids
79
- for (let i = 0; i < inserted.length; i++) {
80
- r.insertedIds[inserted[i].index] = inserted[i]._id;
81
- }
82
-
83
- // Upserted documents
84
- const upserted = r.getUpsertedIds();
85
- // Map upserted ids
86
- for (let i = 0; i < upserted.length; i++) {
87
- r.upsertedIds[upserted[i].index] = upserted[i]._id;
88
- }
89
-
90
73
  // Return the results
91
74
  callback(null, r);
92
75
  });
package/lib/url_parser.js CHANGED
@@ -35,7 +35,8 @@ module.exports = function(url, options, callback) {
35
35
 
36
36
  result.domainLength = result.hostname.split('.').length;
37
37
 
38
- if (result.pathname && result.pathname.match(',')) {
38
+ const hostname = url.substring('mongodb+srv://'.length).split('/')[0];
39
+ if (hostname.match(',')) {
39
40
  return callback(new Error('Invalid URI, cannot contain multiple hostnames'));
40
41
  }
41
42
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb",
3
- "version": "3.6.8",
3
+ "version": "3.6.9",
4
4
  "description": "The official MongoDB driver for Node.js",
5
5
  "main": "index.js",
6
6
  "files": [