@mongosh/shell-api 1.10.0 → 1.10.2
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/.depcheckrc +13 -0
- package/.eslintrc.js +10 -1
- package/.prettierignore +6 -0
- package/.prettierrc.json +1 -0
- package/bin/report-missing-help.ts +12 -4
- package/bin/report-supported-api.ts +2 -1
- package/lib/abstract-cursor.js +5 -5
- package/lib/abstract-cursor.js.map +1 -1
- package/lib/aggregate-or-find-cursor.js +3 -4
- package/lib/aggregate-or-find-cursor.js.map +1 -1
- package/lib/aggregation-cursor.js.map +1 -1
- package/lib/bulk.d.ts +2 -2
- package/lib/bulk.js +6 -7
- package/lib/bulk.js.map +1 -1
- package/lib/change-stream-cursor.d.ts +2 -2
- package/lib/change-stream-cursor.js +1 -1
- package/lib/change-stream-cursor.js.map +1 -1
- package/lib/collection.d.ts +9 -7
- package/lib/collection.js +183 -103
- package/lib/collection.js.map +1 -1
- package/lib/cursor.js +1 -1
- package/lib/cursor.js.map +1 -1
- package/lib/database.d.ts +6 -6
- package/lib/database.js +140 -72
- package/lib/database.js.map +1 -1
- package/lib/dbquery.d.ts +1 -1
- package/lib/dbquery.js +2 -3
- package/lib/dbquery.js.map +1 -1
- package/lib/decorators.d.ts +4 -3
- package/lib/decorators.js +61 -53
- package/lib/decorators.js.map +1 -1
- package/lib/enums.d.ts +1 -1
- package/lib/enums.js +13 -5
- package/lib/enums.js.map +1 -1
- package/lib/error-codes.js +2 -3
- package/lib/error-codes.js.map +1 -1
- package/lib/explainable-cursor.js.map +1 -1
- package/lib/explainable.d.ts +1 -1
- package/lib/explainable.js +37 -12
- package/lib/explainable.js.map +1 -1
- package/lib/field-level-encryption.d.ts +7 -7
- package/lib/field-level-encryption.js +30 -23
- package/lib/field-level-encryption.js.map +1 -1
- package/lib/help.d.ts +3 -3
- package/lib/help.js +5 -2
- package/lib/help.js.map +1 -1
- package/lib/helpers.d.ts +10 -10
- package/lib/helpers.js +141 -85
- package/lib/helpers.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js.map +1 -1
- package/lib/interruptor.js +2 -2
- package/lib/log-entry.d.ts +1 -1
- package/lib/log-entry.js +2 -2
- package/lib/log-entry.js.map +1 -1
- package/lib/mongo-errors.js +10 -5
- package/lib/mongo-errors.js.map +1 -1
- package/lib/mongo.d.ts +5 -4
- package/lib/mongo.js +67 -36
- package/lib/mongo.js.map +1 -1
- package/lib/no-db.d.ts +1 -1
- package/lib/no-db.js +2 -2
- package/lib/no-db.js.map +1 -1
- package/lib/plan-cache.d.ts +3 -3
- package/lib/plan-cache.js +4 -1
- package/lib/plan-cache.js.map +1 -1
- package/lib/replica-set.d.ts +6 -6
- package/lib/replica-set.js +27 -11
- package/lib/replica-set.js.map +1 -1
- package/lib/result.d.ts +1 -1
- package/lib/result.js +14 -21
- package/lib/result.js.map +1 -1
- package/lib/run-command-cursor.js.map +1 -1
- package/lib/session.d.ts +2 -2
- package/lib/session.js.map +1 -1
- package/lib/shard.d.ts +6 -5
- package/lib/shard.js +59 -30
- package/lib/shard.js.map +1 -1
- package/lib/shell-api.d.ts +4 -4
- package/lib/shell-api.js +17 -7
- package/lib/shell-api.js.map +1 -1
- package/lib/shell-bson.d.ts +4 -3
- package/lib/shell-bson.js +38 -16
- package/lib/shell-bson.js.map +1 -1
- package/lib/shell-instance-state.d.ts +5 -4
- package/lib/shell-instance-state.js +33 -20
- package/lib/shell-instance-state.js.map +1 -1
- package/package.json +27 -14
- package/tsconfig-lint.json +5 -0
- package/tsconfig.lint.json +0 -8
package/lib/collection.js
CHANGED
|
@@ -36,7 +36,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
38
|
return database.getCollection(`${name}.${prop}`);
|
|
39
|
-
}
|
|
39
|
+
},
|
|
40
40
|
});
|
|
41
41
|
return proxy;
|
|
42
42
|
}
|
|
@@ -52,7 +52,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
52
52
|
class: 'Collection',
|
|
53
53
|
db: this._database._name,
|
|
54
54
|
coll: this._name,
|
|
55
|
-
arguments: methodArguments
|
|
55
|
+
arguments: methodArguments,
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
async aggregate(...args) {
|
|
@@ -68,7 +68,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
68
68
|
}
|
|
69
69
|
this._emitCollectionApiCall('aggregate', { options, pipeline });
|
|
70
70
|
const { aggOptions, dbOptions, explain } = (0, helpers_1.adaptAggregateOptions)(options);
|
|
71
|
-
const providerCursor = this._mongo._serviceProvider.aggregate(this._database._name, this._name, pipeline, { ...await this._database._baseOptions(), ...aggOptions }, dbOptions);
|
|
71
|
+
const providerCursor = this._mongo._serviceProvider.aggregate(this._database._name, this._name, pipeline, { ...(await this._database._baseOptions()), ...aggOptions }, dbOptions);
|
|
72
72
|
const cursor = new index_1.AggregationCursor(this._mongo, providerCursor);
|
|
73
73
|
if (explain) {
|
|
74
74
|
return await cursor.explain(explain);
|
|
@@ -81,22 +81,22 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
81
81
|
}
|
|
82
82
|
async bulkWrite(operations, options = {}) {
|
|
83
83
|
this._emitCollectionApiCall('bulkWrite', { options });
|
|
84
|
-
const result = await this._mongo._serviceProvider.bulkWrite(this._database._name, this._name, operations, { ...await this._database._baseOptions(), ...options });
|
|
84
|
+
const result = await this._mongo._serviceProvider.bulkWrite(this._database._name, this._name, operations, { ...(await this._database._baseOptions()), ...options });
|
|
85
85
|
return new index_1.BulkWriteResult(!!result.ok, result.insertedCount, result.insertedIds, result.matchedCount, result.modifiedCount, result.deletedCount, result.upsertedCount, result.upsertedIds);
|
|
86
86
|
}
|
|
87
87
|
async count(query = {}, options = {}) {
|
|
88
88
|
await this._instanceState.printDeprecationWarning('Collection.count() is deprecated. Use countDocuments or estimatedDocumentCount.');
|
|
89
89
|
this._emitCollectionApiCall('count', { query, options });
|
|
90
|
-
return this._mongo._serviceProvider.count(this._database._name, this._name, query, { ...await this._database._baseOptions(), ...options });
|
|
90
|
+
return this._mongo._serviceProvider.count(this._database._name, this._name, query, { ...(await this._database._baseOptions()), ...options });
|
|
91
91
|
}
|
|
92
92
|
async countDocuments(query, options = {}) {
|
|
93
93
|
this._emitCollectionApiCall('countDocuments', { query, options });
|
|
94
|
-
return this._mongo._serviceProvider.countDocuments(this._database._name, this._name, query, { ...await this._database._baseOptions(), ...options });
|
|
94
|
+
return this._mongo._serviceProvider.countDocuments(this._database._name, this._name, query, { ...(await this._database._baseOptions()), ...options });
|
|
95
95
|
}
|
|
96
96
|
async deleteMany(filter, options = {}) {
|
|
97
97
|
(0, helpers_1.assertArgsDefinedType)([filter], [true], 'Collection.deleteMany');
|
|
98
98
|
this._emitCollectionApiCall('deleteMany', { filter, options });
|
|
99
|
-
const result = await this._mongo._serviceProvider.deleteMany(this._database._name, this._name, filter, { ...await this._database._baseOptions(), ...options });
|
|
99
|
+
const result = await this._mongo._serviceProvider.deleteMany(this._database._name, this._name, filter, { ...(await this._database._baseOptions()), ...options });
|
|
100
100
|
if (options.explain) {
|
|
101
101
|
return (0, helpers_1.markAsExplainOutput)(result);
|
|
102
102
|
}
|
|
@@ -105,7 +105,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
105
105
|
async deleteOne(filter, options = {}) {
|
|
106
106
|
(0, helpers_1.assertArgsDefinedType)([filter], [true], 'Collection.deleteOne');
|
|
107
107
|
this._emitCollectionApiCall('deleteOne', { filter, options });
|
|
108
|
-
const result = await this._mongo._serviceProvider.deleteOne(this._database._name, this._name, filter, { ...await this._database._baseOptions(), ...options });
|
|
108
|
+
const result = await this._mongo._serviceProvider.deleteOne(this._database._name, this._name, filter, { ...(await this._database._baseOptions()), ...options });
|
|
109
109
|
if (options.explain) {
|
|
110
110
|
return (0, helpers_1.markAsExplainOutput)(result);
|
|
111
111
|
}
|
|
@@ -113,25 +113,27 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
113
113
|
}
|
|
114
114
|
async distinct(field, query, options = {}) {
|
|
115
115
|
this._emitCollectionApiCall('distinct', { field, query, options });
|
|
116
|
-
return (0, helpers_1.maybeMarkAsExplainOutput)(await this._mongo._serviceProvider.distinct(this._database._name, this._name, field, query, { ...await this._database._baseOptions(), ...options }), options);
|
|
116
|
+
return (0, helpers_1.maybeMarkAsExplainOutput)(await this._mongo._serviceProvider.distinct(this._database._name, this._name, field, query, { ...(await this._database._baseOptions()), ...options }), options);
|
|
117
117
|
}
|
|
118
118
|
async estimatedDocumentCount(options = {}) {
|
|
119
119
|
this._emitCollectionApiCall('estimatedDocumentCount', { options });
|
|
120
|
-
return this._mongo._serviceProvider.estimatedDocumentCount(this._database._name, this._name, { ...await this._database._baseOptions(), ...options });
|
|
120
|
+
return this._mongo._serviceProvider.estimatedDocumentCount(this._database._name, this._name, { ...(await this._database._baseOptions()), ...options });
|
|
121
121
|
}
|
|
122
122
|
async find(query, projection, options = {}) {
|
|
123
123
|
if (projection) {
|
|
124
124
|
options.projection = projection;
|
|
125
125
|
}
|
|
126
126
|
this._emitCollectionApiCall('find', { query, options });
|
|
127
|
-
const cursor = new index_1.Cursor(this._mongo, this._mongo._serviceProvider.find(this._database._name, this._name, query, { ...await this._database._baseOptions(), ...options }));
|
|
127
|
+
const cursor = new index_1.Cursor(this._mongo, this._mongo._serviceProvider.find(this._database._name, this._name, query, { ...(await this._database._baseOptions()), ...options }));
|
|
128
128
|
this._mongo._instanceState.currentCursor = cursor;
|
|
129
129
|
return cursor;
|
|
130
130
|
}
|
|
131
131
|
async findAndModify(options) {
|
|
132
132
|
(0, helpers_1.assertArgsDefinedType)([options], [true], 'Collection.findAndModify');
|
|
133
133
|
(0, helpers_1.assertKeysDefined)(options, ['query']);
|
|
134
|
-
this._emitCollectionApiCall('findAndModify', {
|
|
134
|
+
this._emitCollectionApiCall('findAndModify', {
|
|
135
|
+
options: { ...options, update: !!options.update },
|
|
136
|
+
});
|
|
135
137
|
const reducedOptions = { ...options };
|
|
136
138
|
delete reducedOptions.query;
|
|
137
139
|
delete reducedOptions.update;
|
|
@@ -142,7 +144,8 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
142
144
|
if (!update) {
|
|
143
145
|
throw new errors_1.MongoshInvalidInputError('Must specify options.update or options.remove', errors_1.CommonErrors.InvalidArgument);
|
|
144
146
|
}
|
|
145
|
-
if (Array.isArray(update) ||
|
|
147
|
+
if (Array.isArray(update) ||
|
|
148
|
+
Object.keys(update).some((key) => key.startsWith('$'))) {
|
|
146
149
|
return this.findOneAndUpdate(options.query, update, reducedOptions);
|
|
147
150
|
}
|
|
148
151
|
return this.findOneAndReplace(options.query, update, reducedOptions);
|
|
@@ -152,15 +155,17 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
152
155
|
options.projection = projection;
|
|
153
156
|
}
|
|
154
157
|
this._emitCollectionApiCall('findOne', { query, options });
|
|
155
|
-
return new index_1.Cursor(this._mongo, this._mongo._serviceProvider.find(this._database._name, this._name, query, { ...await this._database._baseOptions(), ...options }))
|
|
158
|
+
return new index_1.Cursor(this._mongo, this._mongo._serviceProvider.find(this._database._name, this._name, query, { ...(await this._database._baseOptions()), ...options }))
|
|
159
|
+
.limit(1)
|
|
160
|
+
.tryNext();
|
|
156
161
|
}
|
|
157
162
|
async renameCollection(newName, dropTarget) {
|
|
158
163
|
(0, helpers_1.assertArgsDefinedType)([newName], ['string'], 'Collection.renameCollection');
|
|
159
164
|
this._emitCollectionApiCall('renameCollection', { newName, dropTarget });
|
|
160
165
|
try {
|
|
161
|
-
await this._mongo._serviceProvider.renameCollection(this._database._name, this._name, newName, { ...await this._database._baseOptions(), dropTarget: !!dropTarget });
|
|
166
|
+
await this._mongo._serviceProvider.renameCollection(this._database._name, this._name, newName, { ...(await this._database._baseOptions()), dropTarget: !!dropTarget });
|
|
162
167
|
return {
|
|
163
|
-
ok: 1
|
|
168
|
+
ok: 1,
|
|
164
169
|
};
|
|
165
170
|
}
|
|
166
171
|
catch (e) {
|
|
@@ -169,7 +174,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
169
174
|
ok: 0,
|
|
170
175
|
errmsg: e.errmsg,
|
|
171
176
|
code: e.code,
|
|
172
|
-
codeName: e.codeName
|
|
177
|
+
codeName: e.codeName,
|
|
173
178
|
};
|
|
174
179
|
}
|
|
175
180
|
throw e;
|
|
@@ -178,7 +183,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
178
183
|
async findOneAndDelete(filter, options = {}) {
|
|
179
184
|
(0, helpers_1.assertArgsDefinedType)([filter], [true], 'Collection.findOneAndDelete');
|
|
180
185
|
this._emitCollectionApiCall('findOneAndDelete', { filter, options });
|
|
181
|
-
const result = await this._mongo._serviceProvider.findOneAndDelete(this._database._name, this._name, filter, { ...await this._database._baseOptions(), ...options });
|
|
186
|
+
const result = await this._mongo._serviceProvider.findOneAndDelete(this._database._name, this._name, filter, { ...(await this._database._baseOptions()), ...options });
|
|
182
187
|
if (options.explain) {
|
|
183
188
|
return (0, helpers_1.markAsExplainOutput)(result);
|
|
184
189
|
}
|
|
@@ -187,10 +192,13 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
187
192
|
async findOneAndReplace(filter, replacement, options = {}) {
|
|
188
193
|
(0, helpers_1.assertArgsDefinedType)([filter], [true], 'Collection.findOneAndReplace');
|
|
189
194
|
const findOneAndReplaceOptions = (0, helpers_1.processFindAndModifyOptions)({
|
|
190
|
-
...await this._database._baseOptions(),
|
|
191
|
-
...options
|
|
195
|
+
...(await this._database._baseOptions()),
|
|
196
|
+
...options,
|
|
197
|
+
});
|
|
198
|
+
this._emitCollectionApiCall('findOneAndReplace', {
|
|
199
|
+
filter,
|
|
200
|
+
findOneAndReplaceOptions,
|
|
192
201
|
});
|
|
193
|
-
this._emitCollectionApiCall('findOneAndReplace', { filter, findOneAndReplaceOptions });
|
|
194
202
|
const result = await this._mongo._serviceProvider.findOneAndReplace(this._database._name, this._name, filter, replacement, findOneAndReplaceOptions);
|
|
195
203
|
if (options.explain) {
|
|
196
204
|
return (0, helpers_1.markAsExplainOutput)(result);
|
|
@@ -200,10 +208,13 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
200
208
|
async findOneAndUpdate(filter, update, options = {}) {
|
|
201
209
|
(0, helpers_1.assertArgsDefinedType)([filter], [true], 'Collection.findOneAndUpdate');
|
|
202
210
|
const findOneAndUpdateOptions = (0, helpers_1.processFindAndModifyOptions)({
|
|
203
|
-
...await this._database._baseOptions(),
|
|
204
|
-
...options
|
|
211
|
+
...(await this._database._baseOptions()),
|
|
212
|
+
...options,
|
|
213
|
+
});
|
|
214
|
+
this._emitCollectionApiCall('findOneAndUpdate', {
|
|
215
|
+
filter,
|
|
216
|
+
findOneAndUpdateOptions,
|
|
205
217
|
});
|
|
206
|
-
this._emitCollectionApiCall('findOneAndUpdate', { filter, findOneAndUpdateOptions });
|
|
207
218
|
const result = await this._mongo._serviceProvider.findOneAndUpdate(this._database._name, this._name, filter, update, findOneAndUpdateOptions);
|
|
208
219
|
if (options.explain) {
|
|
209
220
|
return (0, helpers_1.markAsExplainOutput)(result);
|
|
@@ -213,22 +224,26 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
213
224
|
async insert(docs, options = {}) {
|
|
214
225
|
await this._instanceState.printDeprecationWarning('Collection.insert() is deprecated. Use insertOne, insertMany, or bulkWrite.');
|
|
215
226
|
(0, helpers_1.assertArgsDefinedType)([docs], [true], 'Collection.insert');
|
|
216
|
-
const docsToInsert = Array.isArray(docs)
|
|
227
|
+
const docsToInsert = Array.isArray(docs)
|
|
228
|
+
? docs.map((doc) => ({ ...doc }))
|
|
229
|
+
: [{ ...docs }];
|
|
217
230
|
this._emitCollectionApiCall('insert', { options });
|
|
218
|
-
const result = await this._mongo._serviceProvider.insertMany(this._database._name, this._name, docsToInsert, { ...await this._database._baseOptions(), ...options });
|
|
231
|
+
const result = await this._mongo._serviceProvider.insertMany(this._database._name, this._name, docsToInsert, { ...(await this._database._baseOptions()), ...options });
|
|
219
232
|
return new index_1.InsertManyResult(!!result.acknowledged, result.insertedIds);
|
|
220
233
|
}
|
|
221
234
|
async insertMany(docs, options = {}) {
|
|
222
235
|
(0, helpers_1.assertArgsDefinedType)([docs], [true], 'Collection.insertMany');
|
|
223
|
-
const docsToInsert = Array.isArray(docs)
|
|
236
|
+
const docsToInsert = Array.isArray(docs)
|
|
237
|
+
? docs.map((doc) => ({ ...doc }))
|
|
238
|
+
: docs;
|
|
224
239
|
this._emitCollectionApiCall('insertMany', { options });
|
|
225
|
-
const result = await this._mongo._serviceProvider.insertMany(this._database._name, this._name, docsToInsert, { ...await this._database._baseOptions(), ...options });
|
|
240
|
+
const result = await this._mongo._serviceProvider.insertMany(this._database._name, this._name, docsToInsert, { ...(await this._database._baseOptions()), ...options });
|
|
226
241
|
return new index_1.InsertManyResult(!!result.acknowledged, result.insertedIds);
|
|
227
242
|
}
|
|
228
243
|
async insertOne(doc, options = {}) {
|
|
229
244
|
(0, helpers_1.assertArgsDefinedType)([doc], [true], 'Collection.insertOne');
|
|
230
245
|
this._emitCollectionApiCall('insertOne', { options });
|
|
231
|
-
const result = await this._mongo._serviceProvider.insertOne(this._database._name, this._name, { ...doc }, { ...await this._database._baseOptions(), ...options });
|
|
246
|
+
const result = await this._mongo._serviceProvider.insertOne(this._database._name, this._name, { ...doc }, { ...(await this._database._baseOptions()), ...options });
|
|
232
247
|
return new index_1.InsertOneResult(!!result.acknowledged, result.insertedId);
|
|
233
248
|
}
|
|
234
249
|
async isCapped() {
|
|
@@ -247,7 +262,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
247
262
|
const method = removeOptions.justOne ? 'deleteOne' : 'deleteMany';
|
|
248
263
|
delete removeOptions.justOne;
|
|
249
264
|
this._emitCollectionApiCall('remove', { query, removeOptions });
|
|
250
|
-
const result = await this._mongo._serviceProvider[method](this._database._name, this._name, query, { ...await this._database._baseOptions(), ...removeOptions });
|
|
265
|
+
const result = await this._mongo._serviceProvider[method](this._database._name, this._name, query, { ...(await this._database._baseOptions()), ...removeOptions });
|
|
251
266
|
if (removeOptions.explain) {
|
|
252
267
|
return (0, helpers_1.markAsExplainOutput)(result);
|
|
253
268
|
}
|
|
@@ -256,7 +271,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
256
271
|
async replaceOne(filter, replacement, options = {}) {
|
|
257
272
|
(0, helpers_1.assertArgsDefinedType)([filter], [true], 'Collection.replaceOne');
|
|
258
273
|
this._emitCollectionApiCall('replaceOne', { filter, options });
|
|
259
|
-
const result = await this._mongo._serviceProvider.replaceOne(this._database._name, this._name, filter, replacement, { ...await this._database._baseOptions(), ...options });
|
|
274
|
+
const result = await this._mongo._serviceProvider.replaceOne(this._database._name, this._name, filter, replacement, { ...(await this._database._baseOptions()), ...options });
|
|
260
275
|
return new index_1.UpdateResult(!!result.acknowledged, result.matchedCount, result.modifiedCount, result.upsertedCount, result.upsertedId);
|
|
261
276
|
}
|
|
262
277
|
async update(filter, update, options = {}) {
|
|
@@ -265,10 +280,10 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
265
280
|
this._emitCollectionApiCall('update', { filter, options });
|
|
266
281
|
let result;
|
|
267
282
|
if (options.multi) {
|
|
268
|
-
result = await this._mongo._serviceProvider.updateMany(this._database._name, this._name, filter, update, { ...await this._database._baseOptions(), ...options });
|
|
283
|
+
result = await this._mongo._serviceProvider.updateMany(this._database._name, this._name, filter, update, { ...(await this._database._baseOptions()), ...options });
|
|
269
284
|
}
|
|
270
285
|
else {
|
|
271
|
-
result = await this._mongo._serviceProvider.updateOne(this._database._name, this._name, filter, update, { ...await this._database._baseOptions(), ...options });
|
|
286
|
+
result = await this._mongo._serviceProvider.updateOne(this._database._name, this._name, filter, update, { ...(await this._database._baseOptions()), ...options });
|
|
272
287
|
}
|
|
273
288
|
if (options.explain) {
|
|
274
289
|
return (0, helpers_1.markAsExplainOutput)(result);
|
|
@@ -278,7 +293,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
278
293
|
async updateMany(filter, update, options = {}) {
|
|
279
294
|
(0, helpers_1.assertArgsDefinedType)([filter], [true], 'Collection.updateMany');
|
|
280
295
|
this._emitCollectionApiCall('updateMany', { filter, options });
|
|
281
|
-
const result = await this._mongo._serviceProvider.updateMany(this._database._name, this._name, filter, update, { ...await this._database._baseOptions(), ...options });
|
|
296
|
+
const result = await this._mongo._serviceProvider.updateMany(this._database._name, this._name, filter, update, { ...(await this._database._baseOptions()), ...options });
|
|
282
297
|
if (options.explain) {
|
|
283
298
|
return (0, helpers_1.markAsExplainOutput)(result);
|
|
284
299
|
}
|
|
@@ -287,7 +302,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
287
302
|
async updateOne(filter, update, options = {}) {
|
|
288
303
|
(0, helpers_1.assertArgsDefinedType)([filter], [true], 'Collection.updateOne');
|
|
289
304
|
this._emitCollectionApiCall('updateOne', { filter, options });
|
|
290
|
-
const result = await this._mongo._serviceProvider.updateOne(this._database._name, this._name, filter, update, { ...await this._database._baseOptions(), ...options });
|
|
305
|
+
const result = await this._mongo._serviceProvider.updateOne(this._database._name, this._name, filter, update, { ...(await this._database._baseOptions()), ...options });
|
|
291
306
|
if (options.explain) {
|
|
292
307
|
return (0, helpers_1.markAsExplainOutput)(result);
|
|
293
308
|
}
|
|
@@ -298,13 +313,15 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
298
313
|
throw new errors_1.MongoshInvalidInputError('The "compactStructuredEncryptionData" command requires Mongo instance configured with auto encryption.', errors_1.CommonErrors.InvalidArgument);
|
|
299
314
|
}
|
|
300
315
|
this._emitCollectionApiCall('compactStructuredEncryptionData');
|
|
301
|
-
return await this._database._runCommand({
|
|
316
|
+
return await this._database._runCommand({
|
|
317
|
+
compactStructuredEncryptionData: this._name,
|
|
318
|
+
});
|
|
302
319
|
}
|
|
303
320
|
async convertToCapped(size) {
|
|
304
321
|
this._emitCollectionApiCall('convertToCapped', { size });
|
|
305
322
|
return await this._database._runCommand({
|
|
306
323
|
convertToCapped: this._name,
|
|
307
|
-
size
|
|
324
|
+
size,
|
|
308
325
|
});
|
|
309
326
|
}
|
|
310
327
|
async _createIndexes(keyPatterns, options = {}, commitQuorum) {
|
|
@@ -313,9 +330,13 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
313
330
|
throw new errors_1.MongoshInvalidInputError('The "options" argument must be an object.', errors_1.CommonErrors.InvalidArgument);
|
|
314
331
|
}
|
|
315
332
|
const specs = keyPatterns.map((pattern) => ({
|
|
316
|
-
...options,
|
|
333
|
+
...options,
|
|
334
|
+
key: pattern,
|
|
317
335
|
}));
|
|
318
|
-
const createIndexesOptions = {
|
|
336
|
+
const createIndexesOptions = {
|
|
337
|
+
...(await this._database._baseOptions()),
|
|
338
|
+
...options,
|
|
339
|
+
};
|
|
319
340
|
if (undefined !== commitQuorum) {
|
|
320
341
|
createIndexesOptions.commitQuorum = commitQuorum;
|
|
321
342
|
}
|
|
@@ -323,7 +344,8 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
323
344
|
}
|
|
324
345
|
async createIndexes(keyPatterns, options = {}, commitQuorum) {
|
|
325
346
|
const specs = keyPatterns.map((pattern) => ({
|
|
326
|
-
...options,
|
|
347
|
+
...options,
|
|
348
|
+
key: pattern,
|
|
327
349
|
}));
|
|
328
350
|
this._emitCollectionApiCall('createIndexes', { specs });
|
|
329
351
|
return this._createIndexes(keyPatterns, options, commitQuorum);
|
|
@@ -336,7 +358,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
336
358
|
this._emitCollectionApiCall('createIndex', { keys, options });
|
|
337
359
|
const names = await this._createIndexes([keys], options, commitQuorum);
|
|
338
360
|
if (!Array.isArray(names) || names.length !== 1) {
|
|
339
|
-
throw new errors_1.MongoshInternalError(`Expected createIndexes() to return array of length 1, saw ${names}`);
|
|
361
|
+
throw new errors_1.MongoshInternalError(`Expected createIndexes() to return array of length 1, saw ${names.toString()}`);
|
|
340
362
|
}
|
|
341
363
|
return names[0];
|
|
342
364
|
}
|
|
@@ -359,7 +381,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
359
381
|
async getIndexKeys() {
|
|
360
382
|
this._emitCollectionApiCall('getIndexKeys');
|
|
361
383
|
const indexes = await this._mongo._serviceProvider.getIndexes(this._database._name, this._name, await this._database._baseOptions());
|
|
362
|
-
return indexes.map(i => i.key);
|
|
384
|
+
return indexes.map((i) => i.key);
|
|
363
385
|
}
|
|
364
386
|
async dropIndexes(indexes = '*') {
|
|
365
387
|
this._emitCollectionApiCall('dropIndexes', { indexes });
|
|
@@ -370,13 +392,15 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
370
392
|
});
|
|
371
393
|
}
|
|
372
394
|
catch (error) {
|
|
373
|
-
if (((error === null || error === void 0 ? void 0 : error.codeName) === 'IndexNotFound' ||
|
|
374
|
-
(
|
|
395
|
+
if (((error === null || error === void 0 ? void 0 : error.codeName) === 'IndexNotFound' ||
|
|
396
|
+
(error === null || error === void 0 ? void 0 : error.codeName) === undefined) &&
|
|
397
|
+
((error === null || error === void 0 ? void 0 : error.errmsg) === 'invalid index name spec' ||
|
|
398
|
+
(error === null || error === void 0 ? void 0 : error.errmsg) === undefined) &&
|
|
375
399
|
Array.isArray(indexes) &&
|
|
376
400
|
indexes.length > 0 &&
|
|
377
|
-
(await this._database.version())
|
|
401
|
+
/^4\.0\./.exec(await this._database.version())) {
|
|
378
402
|
const all = await Promise.all(indexes.map(async (index) => await this.dropIndexes(index)));
|
|
379
|
-
const errored = all.find(result => !result.ok);
|
|
403
|
+
const errored = all.find((result) => !result.ok);
|
|
380
404
|
if (errored)
|
|
381
405
|
return errored;
|
|
382
406
|
return all.sort((a, b) => b.nIndexesWas - a.nIndexesWas)[0];
|
|
@@ -386,7 +410,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
386
410
|
ok: error.ok,
|
|
387
411
|
errmsg: error.errmsg,
|
|
388
412
|
code: error.code,
|
|
389
|
-
codeName: error.codeName
|
|
413
|
+
codeName: error.codeName,
|
|
390
414
|
};
|
|
391
415
|
}
|
|
392
416
|
throw error;
|
|
@@ -396,7 +420,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
396
420
|
(0, helpers_1.assertArgsDefinedType)([index], [true], 'Collection.dropIndex');
|
|
397
421
|
this._emitCollectionApiCall('dropIndex', { index });
|
|
398
422
|
if (index === '*') {
|
|
399
|
-
throw new errors_1.MongoshInvalidInputError(
|
|
423
|
+
throw new errors_1.MongoshInvalidInputError("To drop indexes in the collection using '*', use db.collection.dropIndexes().", errors_1.CommonErrors.InvalidArgument);
|
|
400
424
|
}
|
|
401
425
|
if (Array.isArray(index)) {
|
|
402
426
|
throw new errors_1.MongoshInvalidInputError('The index to drop must be either the index name or the index specification document.', errors_1.CommonErrors.InvalidArgument);
|
|
@@ -406,7 +430,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
406
430
|
async _getSingleStorageStatValue(key) {
|
|
407
431
|
const cursor = await this.aggregate([
|
|
408
432
|
{ $collStats: { storageStats: {} } },
|
|
409
|
-
{ $group: { _id: null, value: { $sum: `$storageStats.${key}` } } }
|
|
433
|
+
{ $group: { _id: null, value: { $sum: `$storageStats.${key}` } } },
|
|
410
434
|
]);
|
|
411
435
|
const [{ value }] = await cursor.toArray();
|
|
412
436
|
return value;
|
|
@@ -421,7 +445,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
421
445
|
async reIndex() {
|
|
422
446
|
this._emitCollectionApiCall('reIndex');
|
|
423
447
|
return await this._database._runCommand({
|
|
424
|
-
reIndex: this._name
|
|
448
|
+
reIndex: this._name,
|
|
425
449
|
});
|
|
426
450
|
}
|
|
427
451
|
getDB() {
|
|
@@ -453,7 +477,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
453
477
|
if (!encryptedFields && !options.encryptedFields) {
|
|
454
478
|
try {
|
|
455
479
|
const collectionInfos = await this._mongo._serviceProvider.listCollections(this._database._name, {
|
|
456
|
-
name: this._name
|
|
480
|
+
name: this._name,
|
|
457
481
|
}, await this._database._baseOptions());
|
|
458
482
|
const encryptedFields = (_c = (_b = collectionInfos === null || collectionInfos === void 0 ? void 0 : collectionInfos[0]) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.encryptedFields;
|
|
459
483
|
if (encryptedFields) {
|
|
@@ -464,14 +488,18 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
464
488
|
}
|
|
465
489
|
}
|
|
466
490
|
try {
|
|
467
|
-
return await this._mongo._serviceProvider.dropCollection(this._database._name, this._name, {
|
|
491
|
+
return await this._mongo._serviceProvider.dropCollection(this._database._name, this._name, {
|
|
492
|
+
...(await this._database._baseOptions()),
|
|
493
|
+
...options,
|
|
494
|
+
...encryptedFieldsOptions,
|
|
495
|
+
});
|
|
468
496
|
}
|
|
469
497
|
catch (error) {
|
|
470
498
|
if ((error === null || error === void 0 ? void 0 : error.codeName) === 'NamespaceNotFound') {
|
|
471
499
|
this._mongo._instanceState.messageBus.emit('mongosh:warn', {
|
|
472
500
|
method: 'drop',
|
|
473
501
|
class: 'Collection',
|
|
474
|
-
message: `Namespace not found: ${this._name}
|
|
502
|
+
message: `Namespace not found: ${this._name}`,
|
|
475
503
|
});
|
|
476
504
|
return false;
|
|
477
505
|
}
|
|
@@ -481,7 +509,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
481
509
|
async exists() {
|
|
482
510
|
this._emitCollectionApiCall('exists');
|
|
483
511
|
const collectionInfos = await this._mongo._serviceProvider.listCollections(this._database._name, {
|
|
484
|
-
name: this._name
|
|
512
|
+
name: this._name,
|
|
485
513
|
}, await this._database._baseOptions());
|
|
486
514
|
return collectionInfos[0] || null;
|
|
487
515
|
}
|
|
@@ -507,10 +535,12 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
507
535
|
if (typeof commandName === 'string' && !hiddenCommands.test(commandName)) {
|
|
508
536
|
this._emitCollectionApiCall('runCommand', { commandName });
|
|
509
537
|
}
|
|
510
|
-
const cmd = typeof commandName === 'string'
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
538
|
+
const cmd = typeof commandName === 'string'
|
|
539
|
+
? {
|
|
540
|
+
[commandName]: this._name,
|
|
541
|
+
...options,
|
|
542
|
+
}
|
|
543
|
+
: commandName;
|
|
514
544
|
return await this._database._runCommand(cmd);
|
|
515
545
|
}
|
|
516
546
|
explain(verbosity = 'queryPlanner') {
|
|
@@ -521,7 +551,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
521
551
|
async _getLegacyCollStats(scale) {
|
|
522
552
|
const result = await this._database._runCommand({
|
|
523
553
|
collStats: this._name,
|
|
524
|
-
scale: scale || 1
|
|
554
|
+
scale: scale || 1,
|
|
525
555
|
});
|
|
526
556
|
if (!result) {
|
|
527
557
|
throw new errors_1.MongoshRuntimeError(`Error running collStats command on ${this.getFullName()}`, errors_1.CommonErrors.CommandFailed);
|
|
@@ -545,13 +575,18 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
545
575
|
for (const shardResult of collStats) {
|
|
546
576
|
const shardStorageStats = shardResult.storageStats;
|
|
547
577
|
const countField = shardStorageStats.count;
|
|
548
|
-
const shardObjCount =
|
|
578
|
+
const shardObjCount = typeof countField !== 'undefined' ? countField : 0;
|
|
549
579
|
for (const fieldName of Object.keys(shardStorageStats)) {
|
|
550
580
|
if (['ns', 'ok', 'lastExtentSize', 'paddingFactor'].includes(fieldName)) {
|
|
551
581
|
continue;
|
|
552
582
|
}
|
|
553
583
|
if ([
|
|
554
|
-
'userFlags',
|
|
584
|
+
'userFlags',
|
|
585
|
+
'capped',
|
|
586
|
+
'max',
|
|
587
|
+
'paddingFactorNote',
|
|
588
|
+
'indexDetails',
|
|
589
|
+
'wiredTiger',
|
|
555
590
|
].includes(fieldName)) {
|
|
556
591
|
(_a = result[fieldName]) !== null && _a !== void 0 ? _a : (result[fieldName] = shardStorageStats[fieldName]);
|
|
557
592
|
}
|
|
@@ -564,17 +599,27 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
564
599
|
}
|
|
565
600
|
}
|
|
566
601
|
else if (timeseriesStatName === 'avgBucketSize') {
|
|
567
|
-
timeseriesTotalBucketSize +=
|
|
602
|
+
timeseriesTotalBucketSize +=
|
|
603
|
+
(0, helpers_1.coerceToJSNumber)(shardTimeseriesStats.bucketCount) *
|
|
604
|
+
(0, helpers_1.coerceToJSNumber)(timeseriesStat);
|
|
568
605
|
}
|
|
569
606
|
else {
|
|
570
607
|
if (clusterTimeseriesStats[timeseriesStatName] === undefined) {
|
|
571
608
|
clusterTimeseriesStats[timeseriesStatName] = 0;
|
|
572
609
|
}
|
|
573
|
-
clusterTimeseriesStats[timeseriesStatName] +=
|
|
610
|
+
clusterTimeseriesStats[timeseriesStatName] +=
|
|
611
|
+
(0, helpers_1.coerceToJSNumber)(timeseriesStat);
|
|
574
612
|
}
|
|
575
613
|
}
|
|
576
614
|
}
|
|
577
|
-
else if ([
|
|
615
|
+
else if ([
|
|
616
|
+
'count',
|
|
617
|
+
'size',
|
|
618
|
+
'storageSize',
|
|
619
|
+
'totalIndexSize',
|
|
620
|
+
'totalSize',
|
|
621
|
+
'numOrphanDocs',
|
|
622
|
+
].includes(fieldName)) {
|
|
578
623
|
if (counts[fieldName] === undefined) {
|
|
579
624
|
counts[fieldName] = 0;
|
|
580
625
|
}
|
|
@@ -618,7 +663,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
618
663
|
try {
|
|
619
664
|
result.sharded = !!(await config.getCollection('collections').findOne({
|
|
620
665
|
_id: timeseriesBucketsNs !== null && timeseriesBucketsNs !== void 0 ? timeseriesBucketsNs : ns,
|
|
621
|
-
dropped: { $ne: true }
|
|
666
|
+
dropped: { $ne: true },
|
|
622
667
|
}));
|
|
623
668
|
}
|
|
624
669
|
catch (e) {
|
|
@@ -638,7 +683,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
638
683
|
avgBucketSize: clusterTimeseriesStats.bucketCount
|
|
639
684
|
? timeseriesTotalBucketSize / clusterTimeseriesStats.bucketCount
|
|
640
685
|
: 0,
|
|
641
|
-
bucketsNs: timeseriesBucketsNs
|
|
686
|
+
bucketsNs: timeseriesBucketsNs,
|
|
642
687
|
};
|
|
643
688
|
}
|
|
644
689
|
result.indexSizes = {};
|
|
@@ -664,13 +709,15 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
664
709
|
}
|
|
665
710
|
async _getAggregatedCollStats(scale) {
|
|
666
711
|
try {
|
|
667
|
-
const collStats = await (await this.aggregate([
|
|
712
|
+
const collStats = await (await this.aggregate([
|
|
713
|
+
{
|
|
668
714
|
$collStats: {
|
|
669
715
|
storageStats: {
|
|
670
716
|
scale: 1,
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
}
|
|
717
|
+
},
|
|
718
|
+
},
|
|
719
|
+
},
|
|
720
|
+
])).toArray();
|
|
674
721
|
if (!collStats || collStats[0] === undefined) {
|
|
675
722
|
throw new errors_1.MongoshRuntimeError(`Error running $collStats aggregation stage on ${this.getFullName()}`, errors_1.CommonErrors.CommandFailed);
|
|
676
723
|
}
|
|
@@ -690,14 +737,18 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
690
737
|
}
|
|
691
738
|
async stats(originalOptions = {}) {
|
|
692
739
|
var _a;
|
|
693
|
-
const options = typeof originalOptions === 'number'
|
|
740
|
+
const options = typeof originalOptions === 'number'
|
|
741
|
+
? { scale: originalOptions }
|
|
742
|
+
: originalOptions;
|
|
694
743
|
if (options.indexDetailsKey && options.indexDetailsName) {
|
|
695
744
|
throw new errors_1.MongoshInvalidInputError('Cannot filter indexDetails on both indexDetailsKey and indexDetailsName', errors_1.CommonErrors.InvalidArgument);
|
|
696
745
|
}
|
|
697
|
-
if (options.indexDetailsKey &&
|
|
746
|
+
if (options.indexDetailsKey &&
|
|
747
|
+
typeof options.indexDetailsKey !== 'object') {
|
|
698
748
|
throw new errors_1.MongoshInvalidInputError(`Expected options.indexDetailsKey to be a document, got ${typeof options.indexDetailsKey}`, errors_1.CommonErrors.InvalidArgument);
|
|
699
749
|
}
|
|
700
|
-
if (options.indexDetailsName &&
|
|
750
|
+
if (options.indexDetailsName &&
|
|
751
|
+
typeof options.indexDetailsName !== 'string') {
|
|
701
752
|
throw new errors_1.MongoshInvalidInputError(`Expected options.indexDetailsName to be a string, got ${typeof options.indexDetailsName}`, errors_1.CommonErrors.InvalidArgument);
|
|
702
753
|
}
|
|
703
754
|
options.scale = options.scale || 1;
|
|
@@ -758,19 +809,23 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
758
809
|
async mapReduce(map, reduce, optionsOrOutString) {
|
|
759
810
|
await this._instanceState.printDeprecationWarning('Collection.mapReduce() is deprecated. Use an aggregation instead.\nSee https://docs.mongodb.com/manual/core/map-reduce for details.');
|
|
760
811
|
(0, helpers_1.assertArgsDefinedType)([map, reduce, optionsOrOutString], [true, true, true], 'Collection.mapReduce');
|
|
761
|
-
this._emitCollectionApiCall('mapReduce', {
|
|
812
|
+
this._emitCollectionApiCall('mapReduce', {
|
|
813
|
+
map,
|
|
814
|
+
reduce,
|
|
815
|
+
out: optionsOrOutString,
|
|
816
|
+
});
|
|
762
817
|
let cmd = {
|
|
763
818
|
mapReduce: this._name,
|
|
764
819
|
map: map,
|
|
765
820
|
reduce: reduce,
|
|
766
|
-
...(0, helpers_1.processMapReduceOptions)(optionsOrOutString)
|
|
821
|
+
...(0, helpers_1.processMapReduceOptions)(optionsOrOutString),
|
|
767
822
|
};
|
|
768
823
|
if (cmd.explain) {
|
|
769
824
|
const verbosity = cmd.explain;
|
|
770
825
|
delete cmd.explain;
|
|
771
826
|
cmd = {
|
|
772
827
|
explain: cmd,
|
|
773
|
-
verbosity
|
|
828
|
+
verbosity,
|
|
774
829
|
};
|
|
775
830
|
}
|
|
776
831
|
return await this._database._runCommand(cmd);
|
|
@@ -782,13 +837,13 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
782
837
|
}
|
|
783
838
|
return await this._database._runCommand({
|
|
784
839
|
validate: this._name,
|
|
785
|
-
...options
|
|
840
|
+
...options,
|
|
786
841
|
});
|
|
787
842
|
}
|
|
788
843
|
async getShardVersion() {
|
|
789
844
|
this._emitCollectionApiCall('getShardVersion', {});
|
|
790
845
|
return await this._database._runAdminCommand({
|
|
791
|
-
getShardVersion: `${this._database._name}.${this._name}
|
|
846
|
+
getShardVersion: `${this._database._name}.${this._name}`,
|
|
792
847
|
});
|
|
793
848
|
}
|
|
794
849
|
async getShardDistribution() {
|
|
@@ -796,22 +851,29 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
796
851
|
const result = {};
|
|
797
852
|
const config = this._mongo.getDB('config');
|
|
798
853
|
const ns = `${this._database._name}.${this._name}`;
|
|
799
|
-
const configCollectionsInfo = await config
|
|
854
|
+
const configCollectionsInfo = await config
|
|
855
|
+
.getCollection('collections')
|
|
856
|
+
.findOne({
|
|
800
857
|
_id: ns,
|
|
801
|
-
dropped: { $ne: true }
|
|
858
|
+
dropped: { $ne: true },
|
|
802
859
|
});
|
|
803
860
|
if (!configCollectionsInfo) {
|
|
804
861
|
throw new errors_1.MongoshInvalidInputError(`Collection ${this._name} is not sharded`, error_codes_1.ShellApiErrors.NotConnectedToShardedCluster);
|
|
805
862
|
}
|
|
806
|
-
const collStats = await (await this.aggregate({
|
|
863
|
+
const collStats = await (await this.aggregate({ $collStats: { storageStats: {} } })).toArray();
|
|
807
864
|
const totals = { numChunks: 0, size: 0, count: 0 };
|
|
808
865
|
const conciseShardsStats = [];
|
|
809
|
-
await Promise.all(collStats.map((extShardStats) => (
|
|
866
|
+
await Promise.all(collStats.map((extShardStats) => (async () => {
|
|
810
867
|
const { shard } = extShardStats;
|
|
811
|
-
const countChunksQuery = {
|
|
868
|
+
const countChunksQuery = {
|
|
869
|
+
...(0, helpers_1.buildConfigChunksCollectionMatch)(configCollectionsInfo),
|
|
870
|
+
shard,
|
|
871
|
+
};
|
|
812
872
|
const [host, numChunks] = await Promise.all([
|
|
813
|
-
config
|
|
814
|
-
|
|
873
|
+
config
|
|
874
|
+
.getCollection('shards')
|
|
875
|
+
.findOne({ _id: extShardStats.shard }),
|
|
876
|
+
config.getCollection('chunks').countDocuments(countChunksQuery),
|
|
815
877
|
]);
|
|
816
878
|
const shardStats = {
|
|
817
879
|
shardId: shard,
|
|
@@ -819,35 +881,43 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
819
881
|
size: extShardStats.storageStats.size,
|
|
820
882
|
count: extShardStats.storageStats.count,
|
|
821
883
|
numChunks: numChunks,
|
|
822
|
-
avgObjSize: extShardStats.storageStats.avgObjSize
|
|
884
|
+
avgObjSize: extShardStats.storageStats.avgObjSize,
|
|
823
885
|
};
|
|
824
886
|
const key = `Shard ${shardStats.shardId} at ${shardStats.host}`;
|
|
825
|
-
const estChunkData =
|
|
826
|
-
|
|
887
|
+
const estChunkData = shardStats.numChunks === 0
|
|
888
|
+
? 0
|
|
889
|
+
: shardStats.size / shardStats.numChunks;
|
|
890
|
+
const estChunkCount = shardStats.numChunks === 0
|
|
891
|
+
? 0
|
|
892
|
+
: Math.floor(shardStats.count / shardStats.numChunks);
|
|
827
893
|
result[key] = {
|
|
828
894
|
data: (0, helpers_1.dataFormat)((0, helpers_1.coerceToJSNumber)(shardStats.size)),
|
|
829
895
|
docs: shardStats.count,
|
|
830
896
|
chunks: shardStats.numChunks,
|
|
831
897
|
'estimated data per chunk': (0, helpers_1.dataFormat)(estChunkData),
|
|
832
|
-
'estimated docs per chunk': estChunkCount
|
|
898
|
+
'estimated docs per chunk': estChunkCount,
|
|
833
899
|
};
|
|
834
900
|
totals.size += (0, helpers_1.coerceToJSNumber)(shardStats.size);
|
|
835
901
|
totals.count += (0, helpers_1.coerceToJSNumber)(shardStats.count);
|
|
836
902
|
totals.numChunks += (0, helpers_1.coerceToJSNumber)(shardStats.numChunks);
|
|
837
903
|
conciseShardsStats.push(shardStats);
|
|
838
|
-
})()))
|
|
904
|
+
})()));
|
|
839
905
|
const totalValue = {
|
|
840
906
|
data: (0, helpers_1.dataFormat)(totals.size),
|
|
841
907
|
docs: totals.count,
|
|
842
|
-
chunks: totals.numChunks
|
|
908
|
+
chunks: totals.numChunks,
|
|
843
909
|
};
|
|
844
910
|
for (const shardStats of conciseShardsStats) {
|
|
845
|
-
const estDataPercent =
|
|
846
|
-
|
|
911
|
+
const estDataPercent = totals.size === 0
|
|
912
|
+
? 0
|
|
913
|
+
: Math.floor((shardStats.size / totals.size) * 10000) / 100;
|
|
914
|
+
const estDocPercent = totals.count === 0
|
|
915
|
+
? 0
|
|
916
|
+
: Math.floor((shardStats.count / totals.count) * 10000) / 100;
|
|
847
917
|
totalValue[`Shard ${shardStats.shardId}`] = [
|
|
848
918
|
`${estDataPercent} % data`,
|
|
849
919
|
`${estDocPercent} % docs in cluster`,
|
|
850
|
-
`${(0, helpers_1.dataFormat)(shardStats.avgObjSize)} avg obj size on shard
|
|
920
|
+
`${(0, helpers_1.dataFormat)(shardStats.avgObjSize)} avg obj size on shard`,
|
|
851
921
|
];
|
|
852
922
|
}
|
|
853
923
|
result.Totals = totalValue;
|
|
@@ -860,10 +930,12 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
860
930
|
}
|
|
861
931
|
this._emitCollectionApiCall('watch', { pipeline, options });
|
|
862
932
|
const cursor = new change_stream_cursor_1.default(this._mongo._serviceProvider.watch(pipeline, {
|
|
863
|
-
...await this._database._baseOptions(),
|
|
864
|
-
...options
|
|
933
|
+
...(await this._database._baseOptions()),
|
|
934
|
+
...options,
|
|
865
935
|
}, {}, this._database._name, this._name), this._name, this._mongo);
|
|
866
|
-
if (!options.resumeAfter &&
|
|
936
|
+
if (!options.resumeAfter &&
|
|
937
|
+
!options.startAfter &&
|
|
938
|
+
!options.startAtOperationTime) {
|
|
867
939
|
await cursor.tryNext();
|
|
868
940
|
}
|
|
869
941
|
this._mongo._instanceState.currentCursor = cursor;
|
|
@@ -877,25 +949,26 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
877
949
|
this._emitCollectionApiCall('unhideIndex');
|
|
878
950
|
return (0, helpers_1.setHideIndex)(this, index, false);
|
|
879
951
|
}
|
|
880
|
-
async analyzeShardKey(key) {
|
|
952
|
+
async analyzeShardKey(key, options = {}) {
|
|
881
953
|
(0, helpers_1.assertArgsDefinedType)([key], [true], 'Collection.analyzeShardKey');
|
|
882
954
|
this._emitCollectionApiCall('analyzeShardKey', { key });
|
|
883
955
|
return await this._database._runAdminCommand({
|
|
884
956
|
analyzeShardKey: this.getFullName(),
|
|
885
|
-
key
|
|
957
|
+
key,
|
|
958
|
+
...options,
|
|
886
959
|
});
|
|
887
960
|
}
|
|
888
961
|
async configureQueryAnalyzer(options) {
|
|
889
962
|
this._emitCollectionApiCall('configureQueryAnalyzer', options);
|
|
890
963
|
return await this._database._runAdminCommand({
|
|
891
964
|
configureQueryAnalyzer: this.getFullName(),
|
|
892
|
-
...options
|
|
965
|
+
...options,
|
|
893
966
|
});
|
|
894
967
|
}
|
|
895
968
|
async checkMetadataConsistency(options = {}) {
|
|
896
969
|
this._emitCollectionApiCall('checkMetadataConsistency', { options });
|
|
897
970
|
return this._database._runCursorCommand({
|
|
898
|
-
checkMetadataConsistency: this._name
|
|
971
|
+
checkMetadataConsistency: this._name,
|
|
899
972
|
});
|
|
900
973
|
}
|
|
901
974
|
async getSearchIndexes(indexName, options) {
|
|
@@ -904,7 +977,7 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
904
977
|
indexName = undefined;
|
|
905
978
|
}
|
|
906
979
|
this._emitCollectionApiCall('getSearchIndexes', { options });
|
|
907
|
-
return await this._mongo._serviceProvider.getSearchIndexes(this._database._name, this._name, indexName, { ...await this._database._baseOptions(), ...options });
|
|
980
|
+
return await this._mongo._serviceProvider.getSearchIndexes(this._database._name, this._name, indexName, { ...(await this._database._baseOptions()), ...options });
|
|
908
981
|
}
|
|
909
982
|
async createSearchIndex(indexName, definition) {
|
|
910
983
|
var _a;
|
|
@@ -913,7 +986,12 @@ let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
|
913
986
|
indexName = undefined;
|
|
914
987
|
}
|
|
915
988
|
this._emitCollectionApiCall('createSearchIndex', { indexName, definition });
|
|
916
|
-
const results = await this._mongo._serviceProvider.createSearchIndexes(this._database._name, this._name, [
|
|
989
|
+
const results = await this._mongo._serviceProvider.createSearchIndexes(this._database._name, this._name, [
|
|
990
|
+
{
|
|
991
|
+
name: (_a = indexName) !== null && _a !== void 0 ? _a : 'default',
|
|
992
|
+
definition: { ...definition },
|
|
993
|
+
},
|
|
994
|
+
]);
|
|
917
995
|
return results[0];
|
|
918
996
|
}
|
|
919
997
|
async createSearchIndexes(specs) {
|
|
@@ -1202,11 +1280,13 @@ __decorate([
|
|
|
1202
1280
|
(0, decorators_1.apiVersions)([1])
|
|
1203
1281
|
], Collection.prototype, "unhideIndex", null);
|
|
1204
1282
|
__decorate([
|
|
1283
|
+
(0, decorators_1.serverVersions)(['7.0.0', enums_1.ServerVersions.latest]),
|
|
1205
1284
|
decorators_1.returnsPromise,
|
|
1206
1285
|
(0, decorators_1.topologies)([enums_1.Topologies.ReplSet, enums_1.Topologies.Sharded]),
|
|
1207
1286
|
(0, decorators_1.apiVersions)([])
|
|
1208
1287
|
], Collection.prototype, "analyzeShardKey", null);
|
|
1209
1288
|
__decorate([
|
|
1289
|
+
(0, decorators_1.serverVersions)(['7.0.0', enums_1.ServerVersions.latest]),
|
|
1210
1290
|
decorators_1.returnsPromise,
|
|
1211
1291
|
(0, decorators_1.topologies)([enums_1.Topologies.ReplSet, enums_1.Topologies.Sharded]),
|
|
1212
1292
|
(0, decorators_1.apiVersions)([])
|