@mongosh/shell-api 1.10.1 → 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/database.js
CHANGED
|
@@ -42,7 +42,7 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
42
42
|
collections[prop] = new collection_1.default(mongo, proxy, prop);
|
|
43
43
|
}
|
|
44
44
|
return collections[prop];
|
|
45
|
-
}
|
|
45
|
+
},
|
|
46
46
|
});
|
|
47
47
|
return proxy;
|
|
48
48
|
}
|
|
@@ -59,7 +59,7 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
59
59
|
}
|
|
60
60
|
async _maybeCachedHello() {
|
|
61
61
|
var _a;
|
|
62
|
-
return (_a = this._cachedHello) !== null && _a !== void 0 ? _a : await this.hello();
|
|
62
|
+
return (_a = this._cachedHello) !== null && _a !== void 0 ? _a : (await this.hello());
|
|
63
63
|
}
|
|
64
64
|
[enums_1.asPrintable]() {
|
|
65
65
|
return this._name;
|
|
@@ -69,17 +69,28 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
69
69
|
method: methodName,
|
|
70
70
|
class: 'Database',
|
|
71
71
|
db: this._name,
|
|
72
|
-
arguments: methodArguments
|
|
72
|
+
arguments: methodArguments,
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
async _runCommand(cmd, options = {}) {
|
|
76
|
-
return this._mongo._serviceProvider.runCommandWithCheck(this._name, (0, helpers_1.adjustRunCommand)(cmd, this._instanceState.shellBson), {
|
|
76
|
+
return this._mongo._serviceProvider.runCommandWithCheck(this._name, (0, helpers_1.adjustRunCommand)(cmd, this._instanceState.shellBson), {
|
|
77
|
+
...this._mongo._getExplicitlyRequestedReadPref(),
|
|
78
|
+
...(await this._baseOptions()),
|
|
79
|
+
...options,
|
|
80
|
+
});
|
|
77
81
|
}
|
|
78
82
|
async _runAdminCommand(cmd, options = {}) {
|
|
79
|
-
return this.getSiblingDB('admin')._runCommand(cmd, {
|
|
83
|
+
return this.getSiblingDB('admin')._runCommand(cmd, {
|
|
84
|
+
...(await this._baseOptions()),
|
|
85
|
+
...options,
|
|
86
|
+
});
|
|
80
87
|
}
|
|
81
88
|
async _runCursorCommand(cmd, options = {}) {
|
|
82
|
-
const providerCursor = this._mongo._serviceProvider.runCursorCommand(this._name, (0, helpers_1.adjustRunCommand)(cmd, this._instanceState.shellBson), {
|
|
89
|
+
const providerCursor = this._mongo._serviceProvider.runCursorCommand(this._name, (0, helpers_1.adjustRunCommand)(cmd, this._instanceState.shellBson), {
|
|
90
|
+
...this._mongo._getExplicitlyRequestedReadPref(),
|
|
91
|
+
...(await this._baseOptions()),
|
|
92
|
+
...options,
|
|
93
|
+
});
|
|
83
94
|
const cursor = new index_1.RunCommandCursor(this._mongo, providerCursor);
|
|
84
95
|
this._mongo._instanceState.currentCursor = cursor;
|
|
85
96
|
return cursor;
|
|
@@ -88,7 +99,11 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
88
99
|
return this.getSiblingDB('admin')._runCursorCommand(cmd, options);
|
|
89
100
|
}
|
|
90
101
|
async _listCollections(filter, options) {
|
|
91
|
-
return await this._mongo._serviceProvider.listCollections(this._name, filter, {
|
|
102
|
+
return ((await this._mongo._serviceProvider.listCollections(this._name, filter, {
|
|
103
|
+
...this._mongo._getExplicitlyRequestedReadPref(),
|
|
104
|
+
...(await this._baseOptions()),
|
|
105
|
+
...options,
|
|
106
|
+
})) || []);
|
|
92
107
|
}
|
|
93
108
|
async _getCollectionNames(options) {
|
|
94
109
|
const infos = await this._listCollections({}, { ...options, nameOnly: true });
|
|
@@ -97,22 +112,24 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
97
112
|
}
|
|
98
113
|
async _getCollectionNamesWithTypes(options) {
|
|
99
114
|
let collections = await this._listCollections({}, { ...options, nameOnly: true });
|
|
100
|
-
collections = collections.sort((c1, c2) =>
|
|
115
|
+
collections = collections.sort((c1, c2) => c1.name.localeCompare(c2.name));
|
|
101
116
|
this._cachedCollectionNames = collections.map((collection) => collection.name);
|
|
102
117
|
return collections.map((collection, index) => ({
|
|
103
118
|
name: collection.name,
|
|
104
|
-
badge: (0, helpers_1.getBadge)(collections, index)
|
|
119
|
+
badge: (0, helpers_1.getBadge)(collections, index),
|
|
105
120
|
}));
|
|
106
121
|
}
|
|
107
122
|
async _getCollectionNamesForCompletion() {
|
|
108
123
|
return await Promise.race([
|
|
109
124
|
(async () => {
|
|
110
|
-
return await this._getCollectionNames({
|
|
125
|
+
return await this._getCollectionNames({
|
|
126
|
+
readPreference: 'primaryPreferred',
|
|
127
|
+
});
|
|
111
128
|
})(),
|
|
112
129
|
(async () => {
|
|
113
|
-
await new Promise(resolve => setTimeout(resolve, 200).unref());
|
|
130
|
+
await new Promise((resolve) => setTimeout(resolve, 200).unref());
|
|
114
131
|
return this._cachedCollectionNames;
|
|
115
|
-
})()
|
|
132
|
+
})(),
|
|
116
133
|
]);
|
|
117
134
|
}
|
|
118
135
|
async _getLastErrorObj(w, wTimeout, j) {
|
|
@@ -153,7 +170,7 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
153
170
|
cmd = { [cmd]: 1 };
|
|
154
171
|
}
|
|
155
172
|
const hiddenCommands = new RegExp(history_1.HIDDEN_COMMANDS);
|
|
156
|
-
if (!Object.keys(cmd).some(k => hiddenCommands.test(k))) {
|
|
173
|
+
if (!Object.keys(cmd).some((k) => hiddenCommands.test(k))) {
|
|
157
174
|
this._emitDatabaseApiCall('runCommand', { cmd });
|
|
158
175
|
}
|
|
159
176
|
return this._runCommand(cmd);
|
|
@@ -164,7 +181,7 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
164
181
|
cmd = { [cmd]: 1 };
|
|
165
182
|
}
|
|
166
183
|
const hiddenCommands = new RegExp(history_1.HIDDEN_COMMANDS);
|
|
167
|
-
if (!Object.keys(cmd).some(k => hiddenCommands.test(k))) {
|
|
184
|
+
if (!Object.keys(cmd).some((k) => hiddenCommands.test(k))) {
|
|
168
185
|
this._emitDatabaseApiCall('adminCommand', { cmd });
|
|
169
186
|
}
|
|
170
187
|
return await this._runAdminCommand(cmd, {});
|
|
@@ -173,7 +190,7 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
173
190
|
(0, helpers_1.assertArgsDefinedType)([pipeline], [true], 'Database.aggregate');
|
|
174
191
|
this._emitDatabaseApiCall('aggregate', { options, pipeline });
|
|
175
192
|
const { aggOptions, dbOptions, explain } = (0, helpers_1.adaptAggregateOptions)(options);
|
|
176
|
-
const providerCursor = this._mongo._serviceProvider.aggregateDb(this._name, pipeline, { ...await this._baseOptions(), ...aggOptions }, dbOptions);
|
|
193
|
+
const providerCursor = this._mongo._serviceProvider.aggregateDb(this._name, pipeline, { ...(await this._baseOptions()), ...aggOptions }, dbOptions);
|
|
177
194
|
const cursor = new index_1.AggregationCursor(this._mongo, providerCursor);
|
|
178
195
|
if (explain) {
|
|
179
196
|
return await cursor.explain(explain);
|
|
@@ -205,7 +222,10 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
205
222
|
return collections[coll];
|
|
206
223
|
}
|
|
207
224
|
async dropDatabase(writeConcern) {
|
|
208
|
-
return await this._mongo._serviceProvider.dropDatabase(this._name, {
|
|
225
|
+
return await this._mongo._serviceProvider.dropDatabase(this._name, {
|
|
226
|
+
...(await this._baseOptions()),
|
|
227
|
+
writeConcern,
|
|
228
|
+
});
|
|
209
229
|
}
|
|
210
230
|
async createUser(user, writeConcern) {
|
|
211
231
|
(0, helpers_1.assertArgsDefinedType)([user], ['object'], 'Database.createUser');
|
|
@@ -227,23 +247,33 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
227
247
|
command.writeConcern = writeConcern;
|
|
228
248
|
}
|
|
229
249
|
const digestPwd = (0, helpers_1.processDigestPassword)(user.user, user.passwordDigestor, command);
|
|
230
|
-
const orderedCmd = {
|
|
250
|
+
const orderedCmd = {
|
|
251
|
+
createUser: command.createUser,
|
|
252
|
+
...command,
|
|
253
|
+
...digestPwd,
|
|
254
|
+
};
|
|
231
255
|
return await this._runCommand(orderedCmd);
|
|
232
256
|
}
|
|
233
257
|
async updateUser(username, userDoc, writeConcern) {
|
|
234
258
|
(0, helpers_1.assertArgsDefinedType)([username, userDoc], ['string', 'object'], 'Database.updateUser');
|
|
235
259
|
this._emitDatabaseApiCall('updateUser', {});
|
|
236
|
-
if (userDoc.passwordDigestor &&
|
|
260
|
+
if (userDoc.passwordDigestor &&
|
|
261
|
+
userDoc.passwordDigestor !== 'server' &&
|
|
262
|
+
userDoc.passwordDigestor !== 'client') {
|
|
237
263
|
throw new errors_1.MongoshInvalidInputError(`Invalid field: passwordDigestor must be 'client' or 'server', got ${userDoc.passwordDigestor}`, errors_1.CommonErrors.InvalidArgument);
|
|
238
264
|
}
|
|
239
265
|
const command = (0, helpers_1.adaptOptions)({ passwordDigestor: null }, {
|
|
240
|
-
updateUser: username
|
|
266
|
+
updateUser: username,
|
|
241
267
|
}, userDoc);
|
|
242
268
|
if (writeConcern) {
|
|
243
269
|
command.writeConcern = writeConcern;
|
|
244
270
|
}
|
|
245
271
|
const digestPwd = (0, helpers_1.processDigestPassword)(username, userDoc.passwordDigestor, command);
|
|
246
|
-
const orderedCmd = {
|
|
272
|
+
const orderedCmd = {
|
|
273
|
+
updateUser: command.updateUser,
|
|
274
|
+
...command,
|
|
275
|
+
...digestPwd,
|
|
276
|
+
};
|
|
247
277
|
return await this._runCommand(orderedCmd);
|
|
248
278
|
}
|
|
249
279
|
async changeUserPassword(username, password, writeConcern) {
|
|
@@ -251,7 +281,7 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
251
281
|
this._emitDatabaseApiCall('changeUserPassword', {});
|
|
252
282
|
const command = (0, helpers_1.adaptOptions)({}, {
|
|
253
283
|
updateUser: username,
|
|
254
|
-
pwd: password
|
|
284
|
+
pwd: password,
|
|
255
285
|
}, {});
|
|
256
286
|
if (writeConcern) {
|
|
257
287
|
command.writeConcern = writeConcern;
|
|
@@ -289,7 +319,7 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
289
319
|
if (typeof args[0] === 'string' && evaluationListener.onPrompt) {
|
|
290
320
|
authDoc = {
|
|
291
321
|
user: args[0],
|
|
292
|
-
pwd: await evaluationListener.onPrompt('Enter password', 'password')
|
|
322
|
+
pwd: await evaluationListener.onPrompt('Enter password', 'password'),
|
|
293
323
|
};
|
|
294
324
|
}
|
|
295
325
|
else {
|
|
@@ -299,14 +329,14 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
299
329
|
else if (args.length === 2) {
|
|
300
330
|
authDoc = {
|
|
301
331
|
user: args[0],
|
|
302
|
-
pwd: args[1]
|
|
332
|
+
pwd: args[1],
|
|
303
333
|
};
|
|
304
334
|
}
|
|
305
335
|
else {
|
|
306
336
|
throw new errors_1.MongoshInvalidInputError('auth expects (username), (username, password), or ({ user: username, pwd: password })', errors_1.CommonErrors.InvalidArgument);
|
|
307
337
|
}
|
|
308
338
|
if ((!authDoc.user || !authDoc.pwd) && !authDoc.mechanism) {
|
|
309
|
-
throw new errors_1.MongoshInvalidInputError(
|
|
339
|
+
throw new errors_1.MongoshInvalidInputError("auth expects user document with at least 'user' and 'pwd' or 'mechanism' fields", errors_1.CommonErrors.InvalidArgument);
|
|
310
340
|
}
|
|
311
341
|
if ('digestPassword' in authDoc) {
|
|
312
342
|
throw new errors_1.MongoshUnimplementedError('digestPassword is not supported for authentication.', errors_1.CommonErrors.NotImplemented);
|
|
@@ -355,20 +385,33 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
355
385
|
}
|
|
356
386
|
async createCollection(name, options = {}) {
|
|
357
387
|
(0, helpers_1.assertArgsDefinedType)([name], ['string'], 'Database.createCollection');
|
|
358
|
-
this._emitDatabaseApiCall('createCollection', {
|
|
359
|
-
|
|
388
|
+
this._emitDatabaseApiCall('createCollection', {
|
|
389
|
+
name: name,
|
|
390
|
+
options: options,
|
|
391
|
+
});
|
|
392
|
+
return await this._mongo._serviceProvider.createCollection(this._name, name, { ...(await this._baseOptions()), ...options });
|
|
360
393
|
}
|
|
361
394
|
async createEncryptedCollection(name, options) {
|
|
362
|
-
this._emitDatabaseApiCall('createEncryptedCollection', {
|
|
363
|
-
|
|
395
|
+
this._emitDatabaseApiCall('createEncryptedCollection', {
|
|
396
|
+
name: name,
|
|
397
|
+
options: options,
|
|
398
|
+
});
|
|
399
|
+
return this._mongo
|
|
400
|
+
.getClientEncryption()
|
|
401
|
+
.createEncryptedCollection(this._name, name, options);
|
|
364
402
|
}
|
|
365
403
|
async createView(name, source, pipeline, options = {}) {
|
|
366
404
|
(0, helpers_1.assertArgsDefinedType)([name, source, pipeline], ['string', 'string', true], 'Database.createView');
|
|
367
|
-
this._emitDatabaseApiCall('createView', {
|
|
405
|
+
this._emitDatabaseApiCall('createView', {
|
|
406
|
+
name,
|
|
407
|
+
source,
|
|
408
|
+
pipeline,
|
|
409
|
+
options,
|
|
410
|
+
});
|
|
368
411
|
const ccOpts = {
|
|
369
|
-
...await this._baseOptions(),
|
|
412
|
+
...(await this._baseOptions()),
|
|
370
413
|
viewOn: source,
|
|
371
|
-
pipeline: pipeline
|
|
414
|
+
pipeline: pipeline,
|
|
372
415
|
};
|
|
373
416
|
if (options.collation) {
|
|
374
417
|
ccOpts.collation = options.collation;
|
|
@@ -393,7 +436,7 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
393
436
|
(0, helpers_1.assertArgsDefinedType)([rolename, roleDoc], ['string', 'object'], 'Database.updateRole');
|
|
394
437
|
this._emitDatabaseApiCall('updateRole', {});
|
|
395
438
|
const command = (0, helpers_1.adaptOptions)({}, {
|
|
396
|
-
updateRole: rolename
|
|
439
|
+
updateRole: rolename,
|
|
397
440
|
}, roleDoc);
|
|
398
441
|
if (writeConcern) {
|
|
399
442
|
command.writeConcern = writeConcern;
|
|
@@ -439,7 +482,10 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
439
482
|
async grantPrivilegesToRole(rolename, privileges, writeConcern) {
|
|
440
483
|
(0, helpers_1.assertArgsDefinedType)([rolename, privileges], ['string', true], 'Database.grantPrivilegesToRole');
|
|
441
484
|
this._emitDatabaseApiCall('grantPrivilegesToRole', {});
|
|
442
|
-
const cmd = {
|
|
485
|
+
const cmd = {
|
|
486
|
+
grantPrivilegesToRole: rolename,
|
|
487
|
+
privileges: privileges,
|
|
488
|
+
};
|
|
443
489
|
if (writeConcern) {
|
|
444
490
|
cmd.writeConcern = writeConcern;
|
|
445
491
|
}
|
|
@@ -448,7 +494,10 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
448
494
|
async revokePrivilegesFromRole(rolename, privileges, writeConcern) {
|
|
449
495
|
(0, helpers_1.assertArgsDefinedType)([rolename, privileges], ['string', true], 'Database.revokePrivilegesFromRole');
|
|
450
496
|
this._emitDatabaseApiCall('revokePrivilegesFromRole', {});
|
|
451
|
-
const cmd = {
|
|
497
|
+
const cmd = {
|
|
498
|
+
revokePrivilegesFromRole: rolename,
|
|
499
|
+
privileges: privileges,
|
|
500
|
+
};
|
|
452
501
|
if (writeConcern) {
|
|
453
502
|
cmd.writeConcern = writeConcern;
|
|
454
503
|
}
|
|
@@ -476,19 +525,23 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
476
525
|
}
|
|
477
526
|
async _getCurrentOperations(opts) {
|
|
478
527
|
const legacyCurrentOpOptions = typeof opts === 'boolean'
|
|
479
|
-
?
|
|
480
|
-
:
|
|
481
|
-
const pipeline = [
|
|
528
|
+
? { $all: opts, $ownOps: false }
|
|
529
|
+
: { $all: !!opts.$all, $ownOps: !!opts.$ownOps };
|
|
530
|
+
const pipeline = [
|
|
531
|
+
{
|
|
482
532
|
$currentOp: {
|
|
483
533
|
allUsers: !legacyCurrentOpOptions.$ownOps,
|
|
484
534
|
idleConnections: legacyCurrentOpOptions.$all,
|
|
485
535
|
truncateOps: false,
|
|
486
|
-
}
|
|
487
|
-
}
|
|
536
|
+
},
|
|
537
|
+
},
|
|
538
|
+
];
|
|
488
539
|
if (typeof opts === 'object') {
|
|
489
540
|
const matchingFilters = {};
|
|
490
541
|
for (const filtername of Object.keys(opts)) {
|
|
491
|
-
if (filtername !== '$ownOps' &&
|
|
542
|
+
if (filtername !== '$ownOps' &&
|
|
543
|
+
filtername !== '$all' &&
|
|
544
|
+
filtername !== '$truncateOps') {
|
|
492
545
|
matchingFilters[filtername] = opts[filtername];
|
|
493
546
|
}
|
|
494
547
|
}
|
|
@@ -514,35 +567,34 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
514
567
|
const currentOps = await this._getCurrentOperations(opts);
|
|
515
568
|
return {
|
|
516
569
|
inprog: currentOps,
|
|
517
|
-
ok: 1
|
|
570
|
+
ok: 1,
|
|
518
571
|
};
|
|
519
572
|
}
|
|
520
573
|
async killOp(opId) {
|
|
521
|
-
(0, helpers_1.assertArgsDefinedType)([opId], ['number'], 'Database.killOp');
|
|
522
574
|
this._emitDatabaseApiCall('killOp', { opId });
|
|
523
575
|
return await this._runAdminCommand({
|
|
524
576
|
killOp: 1,
|
|
525
|
-
op: opId
|
|
577
|
+
op: opId,
|
|
526
578
|
});
|
|
527
579
|
}
|
|
528
580
|
async shutdownServer(opts = {}) {
|
|
529
581
|
this._emitDatabaseApiCall('shutdownServer', { opts: opts });
|
|
530
582
|
return await this._runAdminCommand({
|
|
531
583
|
shutdown: 1,
|
|
532
|
-
...opts
|
|
584
|
+
...opts,
|
|
533
585
|
});
|
|
534
586
|
}
|
|
535
587
|
async fsyncLock() {
|
|
536
588
|
this._emitDatabaseApiCall('fsyncLock', {});
|
|
537
589
|
return await this._runAdminCommand({
|
|
538
590
|
fsync: 1,
|
|
539
|
-
lock: true
|
|
591
|
+
lock: true,
|
|
540
592
|
});
|
|
541
593
|
}
|
|
542
594
|
async fsyncUnlock() {
|
|
543
595
|
this._emitDatabaseApiCall('fsyncUnlock', {});
|
|
544
596
|
return await this._runAdminCommand({
|
|
545
|
-
fsyncUnlock: 1
|
|
597
|
+
fsyncUnlock: 1,
|
|
546
598
|
});
|
|
547
599
|
}
|
|
548
600
|
async version() {
|
|
@@ -600,7 +652,8 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
600
652
|
async serverStatus(opts = {}) {
|
|
601
653
|
this._emitDatabaseApiCall('serverStatus', { options: opts });
|
|
602
654
|
return await this._runAdminCommand({
|
|
603
|
-
serverStatus: 1,
|
|
655
|
+
serverStatus: 1,
|
|
656
|
+
...opts,
|
|
604
657
|
});
|
|
605
658
|
}
|
|
606
659
|
async stats(scaleOrOptions = 1) {
|
|
@@ -612,7 +665,7 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
612
665
|
return await this._runCommand({
|
|
613
666
|
dbStats: 1,
|
|
614
667
|
scale: 1,
|
|
615
|
-
...scaleOrOptions
|
|
668
|
+
...scaleOrOptions,
|
|
616
669
|
});
|
|
617
670
|
}
|
|
618
671
|
async hostInfo() {
|
|
@@ -630,7 +683,8 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
630
683
|
async rotateCertificates(message) {
|
|
631
684
|
this._emitDatabaseApiCall('rotateCertificates', { message });
|
|
632
685
|
return await this._runAdminCommand({
|
|
633
|
-
rotateCertificates: 1,
|
|
686
|
+
rotateCertificates: 1,
|
|
687
|
+
message,
|
|
634
688
|
});
|
|
635
689
|
}
|
|
636
690
|
async printCollectionStats(scale = 1) {
|
|
@@ -660,7 +714,7 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
660
714
|
this._emitDatabaseApiCall('disableFreeMonitoring', {});
|
|
661
715
|
return await this._runAdminCommand({
|
|
662
716
|
setFreeMonitoring: 1,
|
|
663
|
-
action: 'disable'
|
|
717
|
+
action: 'disable',
|
|
664
718
|
});
|
|
665
719
|
}
|
|
666
720
|
async enableFreeMonitoring() {
|
|
@@ -671,7 +725,7 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
671
725
|
}
|
|
672
726
|
await this._runAdminCommand({
|
|
673
727
|
setFreeMonitoring: 1,
|
|
674
|
-
action: 'enable'
|
|
728
|
+
action: 'enable',
|
|
675
729
|
});
|
|
676
730
|
let result;
|
|
677
731
|
let error;
|
|
@@ -681,8 +735,9 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
681
735
|
catch (err) {
|
|
682
736
|
error = err;
|
|
683
737
|
}
|
|
684
|
-
if (error && error.codeName === 'Unauthorized' ||
|
|
685
|
-
|
|
738
|
+
if ((error && error.codeName === 'Unauthorized') ||
|
|
739
|
+
(result && !result.ok && result.codeName === 'Unauthorized')) {
|
|
740
|
+
return "Unable to determine status as you lack the 'checkFreeMonitoringStatus' privilege.";
|
|
686
741
|
}
|
|
687
742
|
else if (error || !result || !result.ok) {
|
|
688
743
|
throw new errors_1.MongoshRuntimeError(`Error running command setFreeMonitoring ${result ? result.errmsg : error.errmsg}`, errors_1.CommonErrors.CommandFailed);
|
|
@@ -690,7 +745,7 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
690
745
|
if (result.state !== 'enabled') {
|
|
691
746
|
const urlResult = await this._runAdminCommand({
|
|
692
747
|
getParameter: 1,
|
|
693
|
-
cloudFreeMonitoringEndpointURL: 1
|
|
748
|
+
cloudFreeMonitoringEndpointURL: 1,
|
|
694
749
|
});
|
|
695
750
|
return `Unable to get immediate response from the Cloud Monitoring service. Please check your firewall settings to ensure that mongod can communicate with '${urlResult.cloudFreeMonitoringEndpointURL || '<unknown>'}'`;
|
|
696
751
|
}
|
|
@@ -713,12 +768,15 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
713
768
|
this._emitDatabaseApiCall('setProfilingLevel', { opts: opts });
|
|
714
769
|
return await this._runCommand({
|
|
715
770
|
profile: level,
|
|
716
|
-
...opts
|
|
771
|
+
...opts,
|
|
717
772
|
});
|
|
718
773
|
}
|
|
719
774
|
async setLogLevel(logLevel, component) {
|
|
720
775
|
(0, helpers_1.assertArgsDefinedType)([logLevel], ['number'], 'Database.setLogLevel');
|
|
721
|
-
this._emitDatabaseApiCall('setLogLevel', {
|
|
776
|
+
this._emitDatabaseApiCall('setLogLevel', {
|
|
777
|
+
logLevel: logLevel,
|
|
778
|
+
component: component,
|
|
779
|
+
});
|
|
722
780
|
let componentNames = [];
|
|
723
781
|
if (typeof component === 'string') {
|
|
724
782
|
componentNames = component.split('.');
|
|
@@ -786,7 +844,11 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
786
844
|
}
|
|
787
845
|
async getLastErrorObj(w, wTimeout, j) {
|
|
788
846
|
await this._instanceState.printDeprecationWarning('Database.getLastErrorObj() is deprecated and will be removed in the future.');
|
|
789
|
-
this._emitDatabaseApiCall('getLastErrorObj', {
|
|
847
|
+
this._emitDatabaseApiCall('getLastErrorObj', {
|
|
848
|
+
w: w,
|
|
849
|
+
wTimeout: wTimeout,
|
|
850
|
+
j: j,
|
|
851
|
+
});
|
|
790
852
|
return await this._getLastErrorObj(w, wTimeout, j);
|
|
791
853
|
}
|
|
792
854
|
async getLastError(w, wTimeout) {
|
|
@@ -803,8 +865,8 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
803
865
|
async printSecondaryReplicationInfo() {
|
|
804
866
|
let startOptimeDate = null;
|
|
805
867
|
const local = this.getSiblingDB('local');
|
|
806
|
-
if (await local.getCollection('system.replset').countDocuments({}) !== 0) {
|
|
807
|
-
const status = await this._runAdminCommand({
|
|
868
|
+
if ((await local.getCollection('system.replset').countDocuments({})) !== 0) {
|
|
869
|
+
const status = await this._runAdminCommand({ replSetGetStatus: 1 });
|
|
808
870
|
let primary = null;
|
|
809
871
|
for (const member of status.members) {
|
|
810
872
|
if (member.state === 1) {
|
|
@@ -871,7 +933,7 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
871
933
|
const [olStats, first, last] = await Promise.all([
|
|
872
934
|
ol.stats(),
|
|
873
935
|
(async () => (await ol.find()).sort({ $natural: 1 }).limit(1).tryNext())(),
|
|
874
|
-
(async () => (await ol.find()).sort({ $natural: -1 }).limit(1).tryNext())()
|
|
936
|
+
(async () => (await ol.find()).sort({ $natural: -1 }).limit(1).tryNext())(),
|
|
875
937
|
]);
|
|
876
938
|
if (!(olStats === null || olStats === void 0 ? void 0 : olStats.maxSize)) {
|
|
877
939
|
throw new errors_1.MongoshRuntimeError(`Could not get stats for local.${oplog} collection. collstats returned ${JSON.stringify(olStats)}`, errors_1.CommonErrors.CommandFailed);
|
|
@@ -890,8 +952,8 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
890
952
|
tlast = (0, helpers_1.tsToSeconds)(tlast);
|
|
891
953
|
result.timeDiff = tlast - tfirst;
|
|
892
954
|
result.timeDiffHours = Math.round(result.timeDiff / 36) / 100;
|
|
893
|
-
result.tFirst =
|
|
894
|
-
result.tLast =
|
|
955
|
+
result.tFirst = new Date(tfirst * 1000).toString();
|
|
956
|
+
result.tLast = new Date(tlast * 1000).toString();
|
|
895
957
|
result.now = Date();
|
|
896
958
|
}
|
|
897
959
|
else {
|
|
@@ -908,13 +970,15 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
908
970
|
catch (error) {
|
|
909
971
|
const helloResult = await this.hello();
|
|
910
972
|
if (helloResult.arbiterOnly) {
|
|
911
|
-
return new index_1.CommandResult('StatsResult', {
|
|
973
|
+
return new index_1.CommandResult('StatsResult', {
|
|
974
|
+
message: 'cannot provide replication status from an arbiter',
|
|
975
|
+
});
|
|
912
976
|
}
|
|
913
977
|
else if (!helloResult.isWritablePrimary) {
|
|
914
978
|
const secondaryInfo = await this.printSecondaryReplicationInfo();
|
|
915
979
|
return new index_1.CommandResult('StatsResult', {
|
|
916
980
|
message: 'this is a secondary, printing secondary replication info.',
|
|
917
|
-
...secondaryInfo.value
|
|
981
|
+
...secondaryInfo.value,
|
|
918
982
|
});
|
|
919
983
|
}
|
|
920
984
|
throw error;
|
|
@@ -940,10 +1004,12 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
940
1004
|
}
|
|
941
1005
|
this._emitDatabaseApiCall('watch', { pipeline, options });
|
|
942
1006
|
const cursor = new change_stream_cursor_1.default(this._mongo._serviceProvider.watch(pipeline, {
|
|
943
|
-
...await this._baseOptions(),
|
|
944
|
-
...options
|
|
1007
|
+
...(await this._baseOptions()),
|
|
1008
|
+
...options,
|
|
945
1009
|
}, {}, this._name), this._name, this._mongo);
|
|
946
|
-
if (!options.resumeAfter &&
|
|
1010
|
+
if (!options.resumeAfter &&
|
|
1011
|
+
!options.startAfter &&
|
|
1012
|
+
!options.startAtOperationTime) {
|
|
947
1013
|
await cursor.tryNext();
|
|
948
1014
|
}
|
|
949
1015
|
this._mongo._instanceState.currentCursor = cursor;
|
|
@@ -953,14 +1019,16 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
953
1019
|
var _a;
|
|
954
1020
|
this._emitDatabaseApiCall('sql', { sqlString: sqlString, options });
|
|
955
1021
|
await this._instanceState.shellApi.print('Note: this is an experimental feature that may be subject to change in future releases.');
|
|
956
|
-
const cursor = await this.aggregate([
|
|
1022
|
+
const cursor = await this.aggregate([
|
|
1023
|
+
{
|
|
957
1024
|
$sql: {
|
|
958
1025
|
statement: sqlString,
|
|
959
1026
|
format: 'jdbc',
|
|
960
1027
|
dialect: 'mongosql',
|
|
961
|
-
formatVersion: 1
|
|
962
|
-
}
|
|
963
|
-
}
|
|
1028
|
+
formatVersion: 1,
|
|
1029
|
+
},
|
|
1030
|
+
},
|
|
1031
|
+
], options);
|
|
964
1032
|
try {
|
|
965
1033
|
await cursor.hasNext();
|
|
966
1034
|
}
|
|
@@ -975,7 +1043,7 @@ let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
|
975
1043
|
async checkMetadataConsistency(options = {}) {
|
|
976
1044
|
this._emitDatabaseApiCall('checkMetadataConsistency', { options });
|
|
977
1045
|
return this._runCursorCommand({
|
|
978
|
-
checkMetadataConsistency: 1
|
|
1046
|
+
checkMetadataConsistency: 1,
|
|
979
1047
|
});
|
|
980
1048
|
}
|
|
981
1049
|
};
|