@qp-mongosh/shell-api 0.0.0-dev.5 → 0.0.0-dev.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/.eslintignore +2 -2
- package/.eslintrc.js +1 -1
- package/AUTHORS +15 -15
- package/LICENSE +200 -200
- package/bin/report-missing-help.ts +24 -24
- package/bin/report-supported-api.ts +14 -14
- package/lib/abstract-cursor.d.ts +33 -33
- package/lib/abstract-cursor.js +191 -191
- package/lib/aggregation-cursor.d.ts +6 -6
- package/lib/aggregation-cursor.js +19 -19
- package/lib/bulk.d.ts +43 -43
- package/lib/bulk.js +223 -223
- package/lib/change-stream-cursor.d.ts +28 -28
- package/lib/change-stream-cursor.js +111 -111
- package/lib/collection.d.ts +95 -95
- package/lib/collection.js +964 -964
- package/lib/cursor.d.ts +32 -32
- package/lib/cursor.js +215 -215
- package/lib/database.d.ts +116 -116
- package/lib/database.js +1223 -1223
- package/lib/dbquery.d.ts +8 -8
- package/lib/dbquery.js +28 -28
- package/lib/decorators.d.ts +73 -73
- package/lib/decorators.js +395 -395
- package/lib/enums.d.ts +28 -28
- package/lib/enums.js +33 -33
- package/lib/error-codes.d.ts +12 -12
- package/lib/error-codes.js +19 -19
- package/lib/explainable-cursor.d.ts +11 -11
- package/lib/explainable-cursor.js +31 -31
- package/lib/explainable.d.ts +32 -32
- package/lib/explainable.js +166 -166
- package/lib/field-level-encryption.d.ts +50 -50
- package/lib/field-level-encryption.js +176 -176
- package/lib/help.d.ts +22 -22
- package/lib/help.js +26 -26
- package/lib/helpers.d.ts +71 -71
- package/lib/helpers.js +588 -588
- package/lib/index.d.ts +16 -16
- package/lib/index.js +45 -45
- package/lib/interruptor.d.ts +19 -19
- package/lib/interruptor.js +62 -62
- package/lib/mongo-errors.d.ts +5 -5
- package/lib/mongo-errors.js +37 -37
- package/lib/mongo.d.ts +75 -75
- package/lib/mongo.js +476 -476
- package/lib/no-db.d.ts +5 -5
- package/lib/no-db.js +28 -28
- package/lib/plan-cache.d.ts +16 -16
- package/lib/plan-cache.js +70 -70
- package/lib/replica-set.d.ts +45 -45
- package/lib/replica-set.js +314 -314
- package/lib/result.d.ts +61 -61
- package/lib/result.js +104 -104
- package/lib/session.d.ts +25 -25
- package/lib/session.js +88 -88
- package/lib/shard.d.ts +42 -42
- package/lib/shard.js +414 -414
- package/lib/shell-api.d.ts +52 -52
- package/lib/shell-api.js +298 -298
- package/lib/shell-bson.d.ts +40 -40
- package/lib/shell-bson.js +159 -159
- package/lib/shell-instance-state.d.ts +77 -77
- package/lib/shell-instance-state.js +392 -392
- package/package.json +47 -47
- package/tsconfig.lint.json +8 -8
package/lib/database.js
CHANGED
|
@@ -1,1224 +1,1224 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const collection_1 = __importDefault(require("./collection"));
|
|
13
|
-
const decorators_1 = require("./decorators");
|
|
14
|
-
const enums_1 = require("./enums");
|
|
15
|
-
const helpers_1 = require("./helpers");
|
|
16
|
-
const index_1 = require("./index");
|
|
17
|
-
const errors_1 = require("@qp-mongosh/errors");
|
|
18
|
-
const history_1 = require("@qp-mongosh/history");
|
|
19
|
-
const change_stream_cursor_1 = __importDefault(require("./change-stream-cursor"));
|
|
20
|
-
const error_codes_1 = require("./error-codes");
|
|
21
|
-
let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
22
|
-
constructor(mongo, name, session) {
|
|
23
|
-
super();
|
|
24
|
-
this._cachedCollectionNames = [];
|
|
25
|
-
this._cachedHello = null;
|
|
26
|
-
this._mongo = mongo;
|
|
27
|
-
this._name = name;
|
|
28
|
-
const collections = {};
|
|
29
|
-
this._collections = collections;
|
|
30
|
-
this._session = session;
|
|
31
|
-
const proxy = new Proxy(this, {
|
|
32
|
-
get: (target, prop) => {
|
|
33
|
-
if (prop in target) {
|
|
34
|
-
return target[prop];
|
|
35
|
-
}
|
|
36
|
-
if (typeof prop !== 'string' ||
|
|
37
|
-
prop.startsWith('_') ||
|
|
38
|
-
!(0, helpers_1.isValidCollectionName)(prop)) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (!collections[prop]) {
|
|
42
|
-
collections[prop] = new collection_1.default(mongo, proxy, prop);
|
|
43
|
-
}
|
|
44
|
-
return collections[prop];
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
return proxy;
|
|
48
|
-
}
|
|
49
|
-
async _baseOptions() {
|
|
50
|
-
const options = {};
|
|
51
|
-
if (this._session) {
|
|
52
|
-
options.session = this._session._session;
|
|
53
|
-
}
|
|
54
|
-
const maxTimeMS = await this._instanceState.shellApi.config.get('maxTimeMS');
|
|
55
|
-
if (typeof maxTimeMS === 'number') {
|
|
56
|
-
options.maxTimeMS = maxTimeMS;
|
|
57
|
-
}
|
|
58
|
-
return options;
|
|
59
|
-
}
|
|
60
|
-
async _maybeCachedHello() {
|
|
61
|
-
var _a;
|
|
62
|
-
return (_a = this._cachedHello) !== null && _a !== void 0 ? _a : await this.hello();
|
|
63
|
-
}
|
|
64
|
-
[enums_1.asPrintable]() {
|
|
65
|
-
return this._name;
|
|
66
|
-
}
|
|
67
|
-
_emitDatabaseApiCall(methodName, methodArguments = {}) {
|
|
68
|
-
this._mongo._instanceState.emitApiCallWithArgs({
|
|
69
|
-
method: methodName,
|
|
70
|
-
class: 'Database',
|
|
71
|
-
db: this._name,
|
|
72
|
-
arguments: methodArguments
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
async _runCommand(cmd, options = {}) {
|
|
76
|
-
return this._mongo._serviceProvider.runCommandWithCheck(this._name, (0, helpers_1.adjustRunCommand)(cmd, this._instanceState.shellBson), { ...this._mongo._getExplicitlyRequestedReadPref(), ...await this._baseOptions(), ...options });
|
|
77
|
-
}
|
|
78
|
-
async _runAdminCommand(cmd, options = {}) {
|
|
79
|
-
return this.getSiblingDB('admin')._runCommand(cmd, { ...await this._baseOptions(), ...options });
|
|
80
|
-
}
|
|
81
|
-
async _listCollections(filter, options) {
|
|
82
|
-
return await this._mongo._serviceProvider.listCollections(this._name, filter, { ...this._mongo._getExplicitlyRequestedReadPref(), ...await this._baseOptions(), ...options }) || [];
|
|
83
|
-
}
|
|
84
|
-
async _getCollectionNames(options) {
|
|
85
|
-
const infos = await this._listCollections({}, { ...options, nameOnly: true });
|
|
86
|
-
this._cachedCollectionNames = infos.map((collection) => collection.name);
|
|
87
|
-
return this._cachedCollectionNames;
|
|
88
|
-
}
|
|
89
|
-
async _getCollectionNamesWithTypes(options) {
|
|
90
|
-
let collections = await this._listCollections({}, { ...options, nameOnly: true });
|
|
91
|
-
collections = collections.sort((c1, c2) => (c1.name).localeCompare(c2.name));
|
|
92
|
-
const typesToBages = {
|
|
93
|
-
timeseries: '[time-series]',
|
|
94
|
-
view: '[view]'
|
|
95
|
-
};
|
|
96
|
-
this._cachedCollectionNames = collections.map((collection) => collection.name);
|
|
97
|
-
return collections.map((collection) => {
|
|
98
|
-
var _a;
|
|
99
|
-
return ({
|
|
100
|
-
name: collection.name,
|
|
101
|
-
badge: (_a = typesToBages[collection.type]) !== null && _a !== void 0 ? _a : ''
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
async _getCollectionNamesForCompletion() {
|
|
106
|
-
return await Promise.race([
|
|
107
|
-
(async () => {
|
|
108
|
-
return await this._getCollectionNames({ readPreference: 'primaryPreferred' });
|
|
109
|
-
})(),
|
|
110
|
-
(async () => {
|
|
111
|
-
await new Promise(resolve => setTimeout(resolve, 200).unref());
|
|
112
|
-
return this._cachedCollectionNames;
|
|
113
|
-
})()
|
|
114
|
-
]);
|
|
115
|
-
}
|
|
116
|
-
async _getLastErrorObj(w, wTimeout, j) {
|
|
117
|
-
const cmd = { getlasterror: 1 };
|
|
118
|
-
if (w) {
|
|
119
|
-
cmd.w = w;
|
|
120
|
-
}
|
|
121
|
-
if (wTimeout) {
|
|
122
|
-
cmd.wtimeout = wTimeout;
|
|
123
|
-
}
|
|
124
|
-
if (j !== undefined) {
|
|
125
|
-
cmd.j = j;
|
|
126
|
-
}
|
|
127
|
-
try {
|
|
128
|
-
return await this._mongo._serviceProvider.runCommand(this._name, cmd, await this._baseOptions());
|
|
129
|
-
}
|
|
130
|
-
catch (e) {
|
|
131
|
-
return e;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
getMongo() {
|
|
135
|
-
return this._mongo;
|
|
136
|
-
}
|
|
137
|
-
getName() {
|
|
138
|
-
return this._name;
|
|
139
|
-
}
|
|
140
|
-
async getCollectionNames() {
|
|
141
|
-
this._emitDatabaseApiCall('getCollectionNames');
|
|
142
|
-
return this._getCollectionNames();
|
|
143
|
-
}
|
|
144
|
-
async getCollectionInfos(filter = {}, options = {}) {
|
|
145
|
-
this._emitDatabaseApiCall('getCollectionInfos', { filter, options });
|
|
146
|
-
return await this._listCollections(filter, options);
|
|
147
|
-
}
|
|
148
|
-
async runCommand(cmd) {
|
|
149
|
-
(0, helpers_1.assertArgsDefinedType)([cmd], [['string', 'object']], 'Database.runCommand');
|
|
150
|
-
if (typeof cmd === 'string') {
|
|
151
|
-
cmd = { [cmd]: 1 };
|
|
152
|
-
}
|
|
153
|
-
const hiddenCommands = new RegExp(history_1.HIDDEN_COMMANDS);
|
|
154
|
-
if (!Object.keys(cmd).some(k => hiddenCommands.test(k))) {
|
|
155
|
-
this._emitDatabaseApiCall('runCommand', { cmd });
|
|
156
|
-
}
|
|
157
|
-
return this._runCommand(cmd);
|
|
158
|
-
}
|
|
159
|
-
async adminCommand(cmd) {
|
|
160
|
-
(0, helpers_1.assertArgsDefinedType)([cmd], [['string', 'object']], 'Database.adminCommand');
|
|
161
|
-
if (typeof cmd === 'string') {
|
|
162
|
-
cmd = { [cmd]: 1 };
|
|
163
|
-
}
|
|
164
|
-
const hiddenCommands = new RegExp(history_1.HIDDEN_COMMANDS);
|
|
165
|
-
if (!Object.keys(cmd).some(k => hiddenCommands.test(k))) {
|
|
166
|
-
this._emitDatabaseApiCall('adminCommand', { cmd });
|
|
167
|
-
}
|
|
168
|
-
return await this._runAdminCommand(cmd, {});
|
|
169
|
-
}
|
|
170
|
-
async aggregate(pipeline, options) {
|
|
171
|
-
(0, helpers_1.assertArgsDefinedType)([pipeline], [true], 'Database.aggregate');
|
|
172
|
-
this._emitDatabaseApiCall('aggregate', { options, pipeline });
|
|
173
|
-
const { aggOptions, dbOptions, explain } = (0, helpers_1.adaptAggregateOptions)(options);
|
|
174
|
-
const providerCursor = this._mongo._serviceProvider.aggregateDb(this._name, pipeline, { ...await this._baseOptions(), ...aggOptions }, dbOptions);
|
|
175
|
-
const cursor = new index_1.AggregationCursor(this._mongo, providerCursor);
|
|
176
|
-
if (explain) {
|
|
177
|
-
return await cursor.explain(explain);
|
|
178
|
-
}
|
|
179
|
-
else if ((0, helpers_1.shouldRunAggregationImmediately)(pipeline)) {
|
|
180
|
-
await cursor.hasNext();
|
|
181
|
-
}
|
|
182
|
-
this._mongo._instanceState.currentCursor = cursor;
|
|
183
|
-
return cursor;
|
|
184
|
-
}
|
|
185
|
-
getSiblingDB(db) {
|
|
186
|
-
(0, helpers_1.assertArgsDefinedType)([db], ['string'], 'Database.getSiblingDB');
|
|
187
|
-
this._emitDatabaseApiCall('getSiblingDB', { db });
|
|
188
|
-
if (this._session) {
|
|
189
|
-
return this._session.getDatabase(db);
|
|
190
|
-
}
|
|
191
|
-
return this._mongo._getDb(db);
|
|
192
|
-
}
|
|
193
|
-
getCollection(coll) {
|
|
194
|
-
(0, helpers_1.assertArgsDefinedType)([coll], ['string'], 'Database.getColl');
|
|
195
|
-
this._emitDatabaseApiCall('getCollection', { coll });
|
|
196
|
-
if (!(0, helpers_1.isValidCollectionName)(coll)) {
|
|
197
|
-
throw new errors_1.MongoshInvalidInputError(`Invalid collection name: ${coll}`, errors_1.CommonErrors.InvalidArgument);
|
|
198
|
-
}
|
|
199
|
-
const collections = this._collections;
|
|
200
|
-
if (!collections[coll]) {
|
|
201
|
-
collections[coll] = new collection_1.default(this._mongo, this, coll);
|
|
202
|
-
}
|
|
203
|
-
return collections[coll];
|
|
204
|
-
}
|
|
205
|
-
async dropDatabase(writeConcern) {
|
|
206
|
-
return await this._mongo._serviceProvider.dropDatabase(this._name, { ...await this._baseOptions(), writeConcern });
|
|
207
|
-
}
|
|
208
|
-
async createUser(user, writeConcern) {
|
|
209
|
-
(0, helpers_1.assertArgsDefinedType)([user], ['object'], 'Database.createUser');
|
|
210
|
-
(0, helpers_1.assertKeysDefined)(user, ['user', 'roles']);
|
|
211
|
-
if (this._name === '$external') {
|
|
212
|
-
if ('pwd' in user) {
|
|
213
|
-
throw new errors_1.MongoshInvalidInputError('Cannot set password for users on the $external database', errors_1.CommonErrors.InvalidArgument);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
(0, helpers_1.assertKeysDefined)(user, ['pwd']);
|
|
218
|
-
}
|
|
219
|
-
this._emitDatabaseApiCall('createUser', {});
|
|
220
|
-
if (user.createUser) {
|
|
221
|
-
throw new errors_1.MongoshInvalidInputError('Cannot set createUser field in helper method', errors_1.CommonErrors.InvalidArgument);
|
|
222
|
-
}
|
|
223
|
-
const command = (0, helpers_1.adaptOptions)({ user: 'createUser', passwordDigestor: null }, {}, user);
|
|
224
|
-
if (writeConcern) {
|
|
225
|
-
command.writeConcern = writeConcern;
|
|
226
|
-
}
|
|
227
|
-
const digestPwd = (0, helpers_1.processDigestPassword)(user.user, user.passwordDigestor, command);
|
|
228
|
-
const orderedCmd = { createUser: command.createUser, ...command, ...digestPwd };
|
|
229
|
-
return await this._runCommand(orderedCmd);
|
|
230
|
-
}
|
|
231
|
-
async updateUser(username, userDoc, writeConcern) {
|
|
232
|
-
(0, helpers_1.assertArgsDefinedType)([username, userDoc], ['string', 'object'], 'Database.updateUser');
|
|
233
|
-
this._emitDatabaseApiCall('updateUser', {});
|
|
234
|
-
if (userDoc.passwordDigestor && userDoc.passwordDigestor !== 'server' && userDoc.passwordDigestor !== 'client') {
|
|
235
|
-
throw new errors_1.MongoshInvalidInputError(`Invalid field: passwordDigestor must be 'client' or 'server', got ${userDoc.passwordDigestor}`, errors_1.CommonErrors.InvalidArgument);
|
|
236
|
-
}
|
|
237
|
-
const command = (0, helpers_1.adaptOptions)({ passwordDigestor: null }, {
|
|
238
|
-
updateUser: username
|
|
239
|
-
}, userDoc);
|
|
240
|
-
if (writeConcern) {
|
|
241
|
-
command.writeConcern = writeConcern;
|
|
242
|
-
}
|
|
243
|
-
const digestPwd = (0, helpers_1.processDigestPassword)(username, userDoc.passwordDigestor, command);
|
|
244
|
-
const orderedCmd = { updateUser: command.updateUser, ...command, ...digestPwd };
|
|
245
|
-
return await this._runCommand(orderedCmd);
|
|
246
|
-
}
|
|
247
|
-
async changeUserPassword(username, password, writeConcern) {
|
|
248
|
-
(0, helpers_1.assertArgsDefinedType)([username, password], ['string', 'string'], 'Database.changeUserPassword');
|
|
249
|
-
this._emitDatabaseApiCall('changeUserPassword', {});
|
|
250
|
-
const command = (0, helpers_1.adaptOptions)({}, {
|
|
251
|
-
updateUser: username,
|
|
252
|
-
pwd: password
|
|
253
|
-
}, {});
|
|
254
|
-
if (writeConcern) {
|
|
255
|
-
command.writeConcern = writeConcern;
|
|
256
|
-
}
|
|
257
|
-
const orderedCmd = { updateUser: command.updateUser, ...command };
|
|
258
|
-
return await this._runCommand(orderedCmd);
|
|
259
|
-
}
|
|
260
|
-
async logout() {
|
|
261
|
-
this._emitDatabaseApiCall('logout', {});
|
|
262
|
-
this._mongo._instanceState.currentCursor = null;
|
|
263
|
-
return await this._runCommand({ logout: 1 });
|
|
264
|
-
}
|
|
265
|
-
async dropUser(username, writeConcern) {
|
|
266
|
-
(0, helpers_1.assertArgsDefinedType)([username], ['string'], 'Database.dropUser');
|
|
267
|
-
this._emitDatabaseApiCall('dropUser', {});
|
|
268
|
-
const cmd = { dropUser: username };
|
|
269
|
-
if (writeConcern) {
|
|
270
|
-
cmd.writeConcern = writeConcern;
|
|
271
|
-
}
|
|
272
|
-
return await this._runCommand(cmd);
|
|
273
|
-
}
|
|
274
|
-
async dropAllUsers(writeConcern) {
|
|
275
|
-
this._emitDatabaseApiCall('dropAllUsers', {});
|
|
276
|
-
const cmd = { dropAllUsersFromDatabase: 1 };
|
|
277
|
-
if (writeConcern) {
|
|
278
|
-
cmd.writeConcern = writeConcern;
|
|
279
|
-
}
|
|
280
|
-
return await this._runCommand(cmd);
|
|
281
|
-
}
|
|
282
|
-
async auth(...args) {
|
|
283
|
-
this._emitDatabaseApiCall('auth', {});
|
|
284
|
-
let authDoc;
|
|
285
|
-
if (args.length === 1) {
|
|
286
|
-
const { evaluationListener } = this._mongo._instanceState;
|
|
287
|
-
if (typeof args[0] === 'string' && evaluationListener.onPrompt) {
|
|
288
|
-
authDoc = {
|
|
289
|
-
user: args[0],
|
|
290
|
-
pwd: await evaluationListener.onPrompt('Enter password', 'password')
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
authDoc = args[0];
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
else if (args.length === 2) {
|
|
298
|
-
authDoc = {
|
|
299
|
-
user: args[0],
|
|
300
|
-
pwd: args[1]
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
throw new errors_1.MongoshInvalidInputError('auth expects (username), (username, password), or ({ user: username, pwd: password })', errors_1.CommonErrors.InvalidArgument);
|
|
305
|
-
}
|
|
306
|
-
if ((!authDoc.user || !authDoc.pwd) && !authDoc.mechanism) {
|
|
307
|
-
throw new errors_1.MongoshInvalidInputError('auth expects user document with at least \'user\' and \'pwd\' or \'mechanism\' fields', errors_1.CommonErrors.InvalidArgument);
|
|
308
|
-
}
|
|
309
|
-
if ('digestPassword' in authDoc) {
|
|
310
|
-
throw new errors_1.MongoshUnimplementedError('digestPassword is not supported for authentication.', errors_1.CommonErrors.NotImplemented);
|
|
311
|
-
}
|
|
312
|
-
authDoc.authDb = this._name;
|
|
313
|
-
this._mongo._instanceState.currentCursor = null;
|
|
314
|
-
return await this._mongo._serviceProvider.authenticate(authDoc);
|
|
315
|
-
}
|
|
316
|
-
async grantRolesToUser(username, roles, writeConcern) {
|
|
317
|
-
(0, helpers_1.assertArgsDefinedType)([username, roles], ['string', true], 'Database.grantRolesToUser');
|
|
318
|
-
this._emitDatabaseApiCall('grantRolesToUser', {});
|
|
319
|
-
const cmd = { grantRolesToUser: username, roles: roles };
|
|
320
|
-
if (writeConcern) {
|
|
321
|
-
cmd.writeConcern = writeConcern;
|
|
322
|
-
}
|
|
323
|
-
return await this._runCommand(cmd);
|
|
324
|
-
}
|
|
325
|
-
async revokeRolesFromUser(username, roles, writeConcern) {
|
|
326
|
-
(0, helpers_1.assertArgsDefinedType)([username, roles], ['string', true], 'Database.revokeRolesFromUser');
|
|
327
|
-
this._emitDatabaseApiCall('revokeRolesFromUser', {});
|
|
328
|
-
const cmd = { revokeRolesFromUser: username, roles: roles };
|
|
329
|
-
if (writeConcern) {
|
|
330
|
-
cmd.writeConcern = writeConcern;
|
|
331
|
-
}
|
|
332
|
-
return await this._runCommand(cmd);
|
|
333
|
-
}
|
|
334
|
-
async getUser(username, options = {}) {
|
|
335
|
-
(0, helpers_1.assertArgsDefinedType)([username], ['string'], 'Database.getUser');
|
|
336
|
-
this._emitDatabaseApiCall('getUser', { username: username });
|
|
337
|
-
const command = (0, helpers_1.adaptOptions)({}, { usersInfo: { user: username, db: this._name } }, options);
|
|
338
|
-
const result = await this._runCommand(command);
|
|
339
|
-
if (result.users === undefined) {
|
|
340
|
-
throw new errors_1.MongoshInternalError('No users were returned from the userInfo command');
|
|
341
|
-
}
|
|
342
|
-
for (let i = 0; i < result.users.length; i++) {
|
|
343
|
-
if (result.users[i].user === username) {
|
|
344
|
-
return result.users[i];
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return null;
|
|
348
|
-
}
|
|
349
|
-
async getUsers(options = {}) {
|
|
350
|
-
this._emitDatabaseApiCall('getUsers', { options: options });
|
|
351
|
-
const command = (0, helpers_1.adaptOptions)({}, { usersInfo: 1 }, options);
|
|
352
|
-
return await this._runCommand(command);
|
|
353
|
-
}
|
|
354
|
-
async createCollection(name, options = {}) {
|
|
355
|
-
(0, helpers_1.assertArgsDefinedType)([name], ['string'], 'Database.createCollection');
|
|
356
|
-
this._emitDatabaseApiCall('createCollection', { name: name, options: options });
|
|
357
|
-
return await this._mongo._serviceProvider.createCollection(this._name, name, { ...await this._baseOptions(), ...options });
|
|
358
|
-
}
|
|
359
|
-
async createView(name, source, pipeline, options = {}) {
|
|
360
|
-
(0, helpers_1.assertArgsDefinedType)([name, source, pipeline], ['string', 'string', true], 'Database.createView');
|
|
361
|
-
this._emitDatabaseApiCall('createView', { name, source, pipeline, options });
|
|
362
|
-
const ccOpts = {
|
|
363
|
-
...await this._baseOptions(),
|
|
364
|
-
viewOn: source,
|
|
365
|
-
pipeline: pipeline
|
|
366
|
-
};
|
|
367
|
-
if (options.collation) {
|
|
368
|
-
ccOpts.collation = options.collation;
|
|
369
|
-
}
|
|
370
|
-
return await this._mongo._serviceProvider.createCollection(this._name, name, ccOpts);
|
|
371
|
-
}
|
|
372
|
-
async createRole(role, writeConcern) {
|
|
373
|
-
(0, helpers_1.assertArgsDefinedType)([role], ['object'], 'Database.createRole');
|
|
374
|
-
(0, helpers_1.assertKeysDefined)(role, ['role', 'privileges', 'roles']);
|
|
375
|
-
this._emitDatabaseApiCall('createRole', {});
|
|
376
|
-
if (role.createRole) {
|
|
377
|
-
throw new errors_1.MongoshInvalidInputError('Cannot set createRole field in helper method', errors_1.CommonErrors.InvalidArgument);
|
|
378
|
-
}
|
|
379
|
-
const command = (0, helpers_1.adaptOptions)({ role: 'createRole' }, {}, role);
|
|
380
|
-
if (writeConcern) {
|
|
381
|
-
command.writeConcern = writeConcern;
|
|
382
|
-
}
|
|
383
|
-
const orderedCmd = { createRole: command.createRole, ...command };
|
|
384
|
-
return await this._runCommand(orderedCmd);
|
|
385
|
-
}
|
|
386
|
-
async updateRole(rolename, roleDoc, writeConcern) {
|
|
387
|
-
(0, helpers_1.assertArgsDefinedType)([rolename, roleDoc], ['string', 'object'], 'Database.updateRole');
|
|
388
|
-
this._emitDatabaseApiCall('updateRole', {});
|
|
389
|
-
const command = (0, helpers_1.adaptOptions)({}, {
|
|
390
|
-
updateRole: rolename
|
|
391
|
-
}, roleDoc);
|
|
392
|
-
if (writeConcern) {
|
|
393
|
-
command.writeConcern = writeConcern;
|
|
394
|
-
}
|
|
395
|
-
const orderedCmd = { updateRole: command.updateRole, ...command };
|
|
396
|
-
return await this._runCommand(orderedCmd);
|
|
397
|
-
}
|
|
398
|
-
async dropRole(rolename, writeConcern) {
|
|
399
|
-
(0, helpers_1.assertArgsDefinedType)([rolename], ['string'], 'Database.dropRole');
|
|
400
|
-
this._emitDatabaseApiCall('dropRole', {});
|
|
401
|
-
const cmd = { dropRole: rolename };
|
|
402
|
-
if (writeConcern) {
|
|
403
|
-
cmd.writeConcern = writeConcern;
|
|
404
|
-
}
|
|
405
|
-
return await this._runCommand(cmd);
|
|
406
|
-
}
|
|
407
|
-
async dropAllRoles(writeConcern) {
|
|
408
|
-
this._emitDatabaseApiCall('dropAllRoles', {});
|
|
409
|
-
const cmd = { dropAllRolesFromDatabase: 1 };
|
|
410
|
-
if (writeConcern) {
|
|
411
|
-
cmd.writeConcern = writeConcern;
|
|
412
|
-
}
|
|
413
|
-
return await this._runCommand(cmd);
|
|
414
|
-
}
|
|
415
|
-
async grantRolesToRole(rolename, roles, writeConcern) {
|
|
416
|
-
(0, helpers_1.assertArgsDefinedType)([rolename, roles], ['string', true], 'Database.grantRolesToRole');
|
|
417
|
-
this._emitDatabaseApiCall('grantRolesToRole', {});
|
|
418
|
-
const cmd = { grantRolesToRole: rolename, roles: roles };
|
|
419
|
-
if (writeConcern) {
|
|
420
|
-
cmd.writeConcern = writeConcern;
|
|
421
|
-
}
|
|
422
|
-
return await this._runCommand(cmd);
|
|
423
|
-
}
|
|
424
|
-
async revokeRolesFromRole(rolename, roles, writeConcern) {
|
|
425
|
-
(0, helpers_1.assertArgsDefinedType)([rolename, roles], ['string', true], 'Database.revokeRolesFromRole');
|
|
426
|
-
this._emitDatabaseApiCall('revokeRolesFromRole', {});
|
|
427
|
-
const cmd = { revokeRolesFromRole: rolename, roles: roles };
|
|
428
|
-
if (writeConcern) {
|
|
429
|
-
cmd.writeConcern = writeConcern;
|
|
430
|
-
}
|
|
431
|
-
return await this._runCommand(cmd);
|
|
432
|
-
}
|
|
433
|
-
async grantPrivilegesToRole(rolename, privileges, writeConcern) {
|
|
434
|
-
(0, helpers_1.assertArgsDefinedType)([rolename, privileges], ['string', true], 'Database.grantPrivilegesToRole');
|
|
435
|
-
this._emitDatabaseApiCall('grantPrivilegesToRole', {});
|
|
436
|
-
const cmd = { grantPrivilegesToRole: rolename, privileges: privileges };
|
|
437
|
-
if (writeConcern) {
|
|
438
|
-
cmd.writeConcern = writeConcern;
|
|
439
|
-
}
|
|
440
|
-
return await this._runCommand(cmd);
|
|
441
|
-
}
|
|
442
|
-
async revokePrivilegesFromRole(rolename, privileges, writeConcern) {
|
|
443
|
-
(0, helpers_1.assertArgsDefinedType)([rolename, privileges], ['string', true], 'Database.revokePrivilegesFromRole');
|
|
444
|
-
this._emitDatabaseApiCall('revokePrivilegesFromRole', {});
|
|
445
|
-
const cmd = { revokePrivilegesFromRole: rolename, privileges: privileges };
|
|
446
|
-
if (writeConcern) {
|
|
447
|
-
cmd.writeConcern = writeConcern;
|
|
448
|
-
}
|
|
449
|
-
return await this._runCommand(cmd);
|
|
450
|
-
}
|
|
451
|
-
async getRole(rolename, options = {}) {
|
|
452
|
-
(0, helpers_1.assertArgsDefinedType)([rolename], ['string'], 'Database.getRole');
|
|
453
|
-
this._emitDatabaseApiCall('getRole', { rolename: rolename });
|
|
454
|
-
const command = (0, helpers_1.adaptOptions)({}, { rolesInfo: { role: rolename, db: this._name } }, options);
|
|
455
|
-
const result = await this._runCommand(command);
|
|
456
|
-
if (result.roles === undefined) {
|
|
457
|
-
throw new errors_1.MongoshInternalError('No roles returned from rolesInfo command');
|
|
458
|
-
}
|
|
459
|
-
for (let i = 0; i < result.roles.length; i++) {
|
|
460
|
-
if (result.roles[i].role === rolename) {
|
|
461
|
-
return result.roles[i];
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
return null;
|
|
465
|
-
}
|
|
466
|
-
async getRoles(options = {}) {
|
|
467
|
-
this._emitDatabaseApiCall('getRoles', { options: options });
|
|
468
|
-
const command = (0, helpers_1.adaptOptions)({}, { rolesInfo: 1 }, options);
|
|
469
|
-
return await this._runCommand(command);
|
|
470
|
-
}
|
|
471
|
-
async currentOp(opts = {}) {
|
|
472
|
-
this._emitDatabaseApiCall('currentOp', { opts: opts });
|
|
473
|
-
if (typeof opts === 'boolean') {
|
|
474
|
-
opts = { $all: opts };
|
|
475
|
-
}
|
|
476
|
-
return await this._runAdminCommand({
|
|
477
|
-
currentOp: 1,
|
|
478
|
-
...opts
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
async killOp(opId) {
|
|
482
|
-
(0, helpers_1.assertArgsDefinedType)([opId], ['number'], 'Database.killOp');
|
|
483
|
-
this._emitDatabaseApiCall('killOp', { opId });
|
|
484
|
-
return await this._runAdminCommand({
|
|
485
|
-
killOp: 1,
|
|
486
|
-
op: opId
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
async shutdownServer(opts = {}) {
|
|
490
|
-
this._emitDatabaseApiCall('shutdownServer', { opts: opts });
|
|
491
|
-
return await this._runAdminCommand({
|
|
492
|
-
shutdown: 1,
|
|
493
|
-
...opts
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
async fsyncLock() {
|
|
497
|
-
this._emitDatabaseApiCall('fsyncLock', {});
|
|
498
|
-
return await this._runAdminCommand({
|
|
499
|
-
fsync: 1,
|
|
500
|
-
lock: true
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
async fsyncUnlock() {
|
|
504
|
-
this._emitDatabaseApiCall('fsyncUnlock', {});
|
|
505
|
-
return await this._runAdminCommand({
|
|
506
|
-
fsyncUnlock: 1
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
async version() {
|
|
510
|
-
this._emitDatabaseApiCall('version', {});
|
|
511
|
-
const info = await this._runAdminCommand({
|
|
512
|
-
buildInfo: 1,
|
|
513
|
-
});
|
|
514
|
-
if (!info || info.version === undefined) {
|
|
515
|
-
throw new errors_1.MongoshRuntimeError(`Error running command serverBuildInfo ${info ? info.errmsg || '' : ''}`, errors_1.CommonErrors.CommandFailed);
|
|
516
|
-
}
|
|
517
|
-
return info.version;
|
|
518
|
-
}
|
|
519
|
-
async serverBits() {
|
|
520
|
-
this._emitDatabaseApiCall('serverBits', {});
|
|
521
|
-
const info = await this._runAdminCommand({
|
|
522
|
-
buildInfo: 1,
|
|
523
|
-
});
|
|
524
|
-
if (!info || info.bits === undefined) {
|
|
525
|
-
throw new errors_1.MongoshRuntimeError(`Error running command serverBuildInfo ${info ? info.errmsg || '' : ''}`, errors_1.CommonErrors.CommandFailed);
|
|
526
|
-
}
|
|
527
|
-
return info.bits;
|
|
528
|
-
}
|
|
529
|
-
async isMaster() {
|
|
530
|
-
this._emitDatabaseApiCall('isMaster', {});
|
|
531
|
-
const result = await this._runCommand({
|
|
532
|
-
isMaster: 1,
|
|
533
|
-
});
|
|
534
|
-
result.isWritablePrimary = result.ismaster;
|
|
535
|
-
return result;
|
|
536
|
-
}
|
|
537
|
-
async hello() {
|
|
538
|
-
this._emitDatabaseApiCall('hello', {});
|
|
539
|
-
try {
|
|
540
|
-
this._cachedHello = await this._runCommand({
|
|
541
|
-
hello: 1,
|
|
542
|
-
});
|
|
543
|
-
return this._cachedHello;
|
|
544
|
-
}
|
|
545
|
-
catch (err) {
|
|
546
|
-
if ((err === null || err === void 0 ? void 0 : err.codeName) === 'CommandNotFound') {
|
|
547
|
-
const result = await this.isMaster();
|
|
548
|
-
delete result.ismaster;
|
|
549
|
-
this._cachedHello = result;
|
|
550
|
-
return this._cachedHello;
|
|
551
|
-
}
|
|
552
|
-
throw err;
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
async serverBuildInfo() {
|
|
556
|
-
this._emitDatabaseApiCall('serverBuildInfo', {});
|
|
557
|
-
return await this._runAdminCommand({
|
|
558
|
-
buildInfo: 1,
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
async serverStatus(opts = {}) {
|
|
562
|
-
this._emitDatabaseApiCall('serverStatus', { options: opts });
|
|
563
|
-
return await this._runAdminCommand({
|
|
564
|
-
serverStatus: 1, ...opts
|
|
565
|
-
});
|
|
566
|
-
}
|
|
567
|
-
async stats(scaleOrOptions = 1) {
|
|
568
|
-
(0, helpers_1.assertArgsDefinedType)([scaleOrOptions], [['number', 'object']], 'Database.stats');
|
|
569
|
-
if (typeof scaleOrOptions === 'number') {
|
|
570
|
-
scaleOrOptions = { scale: scaleOrOptions };
|
|
571
|
-
}
|
|
572
|
-
this._emitDatabaseApiCall('stats', { scale: scaleOrOptions.scale });
|
|
573
|
-
return await this._runCommand({
|
|
574
|
-
dbStats: 1,
|
|
575
|
-
scale: 1,
|
|
576
|
-
...scaleOrOptions
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
async hostInfo() {
|
|
580
|
-
this._emitDatabaseApiCall('hostInfo', {});
|
|
581
|
-
return await this._runAdminCommand({
|
|
582
|
-
hostInfo: 1,
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
async serverCmdLineOpts() {
|
|
586
|
-
this._emitDatabaseApiCall('serverCmdLineOpts', {});
|
|
587
|
-
return await this._runAdminCommand({
|
|
588
|
-
getCmdLineOpts: 1,
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
async rotateCertificates(message) {
|
|
592
|
-
this._emitDatabaseApiCall('rotateCertificates', { message });
|
|
593
|
-
return await this._runAdminCommand({
|
|
594
|
-
rotateCertificates: 1, message
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
async printCollectionStats(scale = 1) {
|
|
598
|
-
if (typeof scale !== 'number' || scale < 1) {
|
|
599
|
-
throw new errors_1.MongoshInvalidInputError(`scale has to be a number >=1, got ${scale}`, errors_1.CommonErrors.InvalidArgument);
|
|
600
|
-
}
|
|
601
|
-
this._emitDatabaseApiCall('printCollectionStats', { scale: scale });
|
|
602
|
-
const colls = await this.getCollectionNames();
|
|
603
|
-
const result = {};
|
|
604
|
-
for (const c of colls) {
|
|
605
|
-
try {
|
|
606
|
-
result[c] = await this.getCollection(c).stats({ scale });
|
|
607
|
-
}
|
|
608
|
-
catch (error) {
|
|
609
|
-
result[c] = { ok: 0, errmsg: error === null || error === void 0 ? void 0 : error.message };
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
return new index_1.CommandResult('StatsResult', result);
|
|
613
|
-
}
|
|
614
|
-
async getFreeMonitoringStatus() {
|
|
615
|
-
this._emitDatabaseApiCall('getFreeMonitoringStatus', {});
|
|
616
|
-
return await this._runAdminCommand({
|
|
617
|
-
getFreeMonitoringStatus: 1,
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
async disableFreeMonitoring() {
|
|
621
|
-
this._emitDatabaseApiCall('disableFreeMonitoring', {});
|
|
622
|
-
return await this._runAdminCommand({
|
|
623
|
-
setFreeMonitoring: 1,
|
|
624
|
-
action: 'disable'
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
async enableFreeMonitoring() {
|
|
628
|
-
this._emitDatabaseApiCall('enableFreeMonitoring', {});
|
|
629
|
-
const helloResult = await this.hello();
|
|
630
|
-
if (!helloResult.isWritablePrimary) {
|
|
631
|
-
throw new errors_1.MongoshInvalidInputError('db.enableFreeMonitoring() may only be run on a primary', errors_1.CommonErrors.InvalidOperation);
|
|
632
|
-
}
|
|
633
|
-
await this._runAdminCommand({
|
|
634
|
-
setFreeMonitoring: 1,
|
|
635
|
-
action: 'enable'
|
|
636
|
-
});
|
|
637
|
-
let result;
|
|
638
|
-
let error;
|
|
639
|
-
try {
|
|
640
|
-
result = await this._runAdminCommand({ getFreeMonitoringStatus: 1 });
|
|
641
|
-
}
|
|
642
|
-
catch (err) {
|
|
643
|
-
error = err;
|
|
644
|
-
}
|
|
645
|
-
if (error && error.codeName === 'Unauthorized' || (result && !result.ok && result.codeName === 'Unauthorized')) {
|
|
646
|
-
return 'Unable to determine status as you lack the \'checkFreeMonitoringStatus\' privilege.';
|
|
647
|
-
}
|
|
648
|
-
else if (error || !result || !result.ok) {
|
|
649
|
-
throw new errors_1.MongoshRuntimeError(`Error running command setFreeMonitoring ${result ? result.errmsg : error.errmsg}`, errors_1.CommonErrors.CommandFailed);
|
|
650
|
-
}
|
|
651
|
-
if (result.state !== 'enabled') {
|
|
652
|
-
const urlResult = await this._runAdminCommand({
|
|
653
|
-
getParameter: 1,
|
|
654
|
-
cloudFreeMonitoringEndpointURL: 1
|
|
655
|
-
});
|
|
656
|
-
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>'}'`;
|
|
657
|
-
}
|
|
658
|
-
return result;
|
|
659
|
-
}
|
|
660
|
-
async getProfilingStatus() {
|
|
661
|
-
this._emitDatabaseApiCall('getProfilingStatus', {});
|
|
662
|
-
return await this._runCommand({
|
|
663
|
-
profile: -1,
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
async setProfilingLevel(level, opts = {}) {
|
|
667
|
-
(0, helpers_1.assertArgsDefinedType)([level], ['number'], 'Database.setProfilingLevel');
|
|
668
|
-
if (level < 0 || level > 2) {
|
|
669
|
-
throw new errors_1.MongoshInvalidInputError(`Input level ${level} is out of range [0..2]`, errors_1.CommonErrors.InvalidArgument);
|
|
670
|
-
}
|
|
671
|
-
if (typeof opts === 'number') {
|
|
672
|
-
opts = { slowms: opts };
|
|
673
|
-
}
|
|
674
|
-
this._emitDatabaseApiCall('setProfilingLevel', { opts: opts });
|
|
675
|
-
return await this._runCommand({
|
|
676
|
-
profile: level,
|
|
677
|
-
...opts
|
|
678
|
-
});
|
|
679
|
-
}
|
|
680
|
-
async setLogLevel(logLevel, component) {
|
|
681
|
-
(0, helpers_1.assertArgsDefinedType)([logLevel], ['number'], 'Database.setLogLevel');
|
|
682
|
-
this._emitDatabaseApiCall('setLogLevel', { logLevel: logLevel, component: component });
|
|
683
|
-
let componentNames = [];
|
|
684
|
-
if (typeof component === 'string') {
|
|
685
|
-
componentNames = component.split('.');
|
|
686
|
-
}
|
|
687
|
-
else if (component !== undefined) {
|
|
688
|
-
throw new errors_1.MongoshInvalidInputError(`setLogLevel component must be a string: got ${typeof component}`, errors_1.CommonErrors.InvalidArgument);
|
|
689
|
-
}
|
|
690
|
-
let vDoc = { verbosity: logLevel };
|
|
691
|
-
while (componentNames.length > 0) {
|
|
692
|
-
const key = componentNames.pop();
|
|
693
|
-
vDoc = { [key]: vDoc };
|
|
694
|
-
}
|
|
695
|
-
const cmdObj = { setParameter: 1, logComponentVerbosity: vDoc };
|
|
696
|
-
return await this._runAdminCommand(cmdObj);
|
|
697
|
-
}
|
|
698
|
-
async getLogComponents() {
|
|
699
|
-
this._emitDatabaseApiCall('getLogComponents', {});
|
|
700
|
-
const cmdObj = { getParameter: 1, logComponentVerbosity: 1 };
|
|
701
|
-
const result = await this._runAdminCommand(cmdObj);
|
|
702
|
-
if (!result || result.logComponentVerbosity === undefined) {
|
|
703
|
-
throw new errors_1.MongoshRuntimeError(`Error running command ${result ? result.errmsg || '' : ''}`, errors_1.CommonErrors.CommandFailed);
|
|
704
|
-
}
|
|
705
|
-
return result.logComponentVerbosity;
|
|
706
|
-
}
|
|
707
|
-
cloneDatabase() {
|
|
708
|
-
throw new errors_1.MongoshDeprecatedError('`cloneDatabase()` was removed because it was deprecated in MongoDB 4.0');
|
|
709
|
-
}
|
|
710
|
-
cloneCollection() {
|
|
711
|
-
throw new errors_1.MongoshDeprecatedError('`cloneCollection()` was removed because it was deprecated in MongoDB 4.0');
|
|
712
|
-
}
|
|
713
|
-
copyDatabase() {
|
|
714
|
-
throw new errors_1.MongoshDeprecatedError('`copyDatabase()` was removed because it was deprecated in MongoDB 4.0');
|
|
715
|
-
}
|
|
716
|
-
async commandHelp(name) {
|
|
717
|
-
(0, helpers_1.assertArgsDefinedType)([name], ['string'], 'Database.commandHelp');
|
|
718
|
-
this._emitDatabaseApiCall('commandHelp', { name: name });
|
|
719
|
-
const command = {};
|
|
720
|
-
command[name] = 1;
|
|
721
|
-
command.help = true;
|
|
722
|
-
const result = await this._runCommand(command);
|
|
723
|
-
if (!result || result.help === undefined) {
|
|
724
|
-
throw new errors_1.MongoshRuntimeError(`Error running command commandHelp ${result ? result.errmsg || '' : ''}`, errors_1.CommonErrors.CommandFailed);
|
|
725
|
-
}
|
|
726
|
-
return result.help;
|
|
727
|
-
}
|
|
728
|
-
async listCommands() {
|
|
729
|
-
this._emitDatabaseApiCall('listCommands', {});
|
|
730
|
-
const result = await this._runCommand({
|
|
731
|
-
listCommands: 1,
|
|
732
|
-
});
|
|
733
|
-
if (!result || result.commands === undefined) {
|
|
734
|
-
throw new errors_1.MongoshRuntimeError(`Error running command listCommands ${result ? result.errmsg || '' : ''}`, errors_1.CommonErrors.CommandFailed);
|
|
735
|
-
}
|
|
736
|
-
for (const cmdDescription of Object.values(result.commands)) {
|
|
737
|
-
if ('slaveOk' in cmdDescription) {
|
|
738
|
-
cmdDescription.secondaryOk = cmdDescription.slaveOk;
|
|
739
|
-
delete cmdDescription.slaveOk;
|
|
740
|
-
}
|
|
741
|
-
if ('slaveOverrideOk' in cmdDescription) {
|
|
742
|
-
cmdDescription.secondaryOverrideOk = cmdDescription.slaveOverrideOk;
|
|
743
|
-
delete cmdDescription.slaveOverrideOk;
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
return new index_1.CommandResult('ListCommandsResult', result.commands);
|
|
747
|
-
}
|
|
748
|
-
async getLastErrorObj(w, wTimeout, j) {
|
|
749
|
-
await this._instanceState.printDeprecationWarning('Database.getLastErrorObj() is deprecated and will be removed in the future.');
|
|
750
|
-
this._emitDatabaseApiCall('getLastErrorObj', { w: w, wTimeout: wTimeout, j: j });
|
|
751
|
-
return await this._getLastErrorObj(w, wTimeout, j);
|
|
752
|
-
}
|
|
753
|
-
async getLastError(w, wTimeout) {
|
|
754
|
-
await this._instanceState.printDeprecationWarning('Database.getLastError() is deprecated and will be removed in the future.');
|
|
755
|
-
this._emitDatabaseApiCall('getLastError', { w: w, wTimeout: wTimeout });
|
|
756
|
-
const result = await this._getLastErrorObj(w, wTimeout);
|
|
757
|
-
return result.err || null;
|
|
758
|
-
}
|
|
759
|
-
async printShardingStatus(verbose = false) {
|
|
760
|
-
this._emitDatabaseApiCall('printShardingStatus', { verbose });
|
|
761
|
-
const result = await (0, helpers_1.getPrintableShardStatus)(await (0, helpers_1.getConfigDB)(this), verbose);
|
|
762
|
-
return new index_1.CommandResult('StatsResult', result);
|
|
763
|
-
}
|
|
764
|
-
async printSecondaryReplicationInfo() {
|
|
765
|
-
let startOptimeDate = null;
|
|
766
|
-
const local = this.getSiblingDB('local');
|
|
767
|
-
if (await local.getCollection('system.replset').countDocuments({}) !== 0) {
|
|
768
|
-
const status = await this._runAdminCommand({ 'replSetGetStatus': 1 });
|
|
769
|
-
let primary = null;
|
|
770
|
-
for (const member of status.members) {
|
|
771
|
-
if (member.state === 1) {
|
|
772
|
-
primary = member;
|
|
773
|
-
break;
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
if (primary) {
|
|
777
|
-
startOptimeDate = primary.optimeDate;
|
|
778
|
-
}
|
|
779
|
-
else {
|
|
780
|
-
startOptimeDate = new Date(0, 0);
|
|
781
|
-
for (const member of status.members) {
|
|
782
|
-
if (member.optimeDate > startOptimeDate) {
|
|
783
|
-
startOptimeDate = member.optimeDate;
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
const result = {};
|
|
788
|
-
for (const node of status.members) {
|
|
789
|
-
const nodeResult = {};
|
|
790
|
-
if (node === null || node === undefined) {
|
|
791
|
-
throw new errors_1.MongoshRuntimeError('Member returned from command replSetGetStatus is null', errors_1.CommonErrors.CommandFailed);
|
|
792
|
-
}
|
|
793
|
-
if (node.state === 1 || node.state === 7) {
|
|
794
|
-
continue;
|
|
795
|
-
}
|
|
796
|
-
if (node.optime && node.health !== 0) {
|
|
797
|
-
if (startOptimeDate === null || startOptimeDate === undefined) {
|
|
798
|
-
throw new errors_1.MongoshRuntimeError('getReplLag startOptimeDate is null', errors_1.CommonErrors.CommandFailed);
|
|
799
|
-
}
|
|
800
|
-
if (startOptimeDate) {
|
|
801
|
-
nodeResult.syncedTo = node.optimeDate.toString();
|
|
802
|
-
}
|
|
803
|
-
const ago = (node.optimeDate - startOptimeDate) / 1000;
|
|
804
|
-
const hrs = Math.round(ago / 36) / 100;
|
|
805
|
-
let suffix = '';
|
|
806
|
-
if (primary) {
|
|
807
|
-
suffix = 'primary ';
|
|
808
|
-
}
|
|
809
|
-
else {
|
|
810
|
-
suffix = 'freshest member (no primary available at the moment)';
|
|
811
|
-
}
|
|
812
|
-
nodeResult.replLag = `${Math.round(ago)} secs (${hrs} hrs) behind the ${suffix}`;
|
|
813
|
-
}
|
|
814
|
-
else {
|
|
815
|
-
nodeResult['no replication info, yet. State'] = node.stateStr;
|
|
816
|
-
}
|
|
817
|
-
result[`source: ${node.name}`] = nodeResult;
|
|
818
|
-
}
|
|
819
|
-
return new index_1.CommandResult('StatsResult', result);
|
|
820
|
-
}
|
|
821
|
-
throw new errors_1.MongoshInvalidInputError('local.system.replset is empty. Are you connected to a replica set?', error_codes_1.ShellApiErrors.NotConnectedToReplicaSet);
|
|
822
|
-
}
|
|
823
|
-
async getReplicationInfo() {
|
|
824
|
-
const localdb = this.getSiblingDB('local');
|
|
825
|
-
const result = {};
|
|
826
|
-
const oplog = 'oplog.rs';
|
|
827
|
-
const localCollections = await localdb.getCollectionNames();
|
|
828
|
-
if (!localCollections.includes(oplog)) {
|
|
829
|
-
throw new errors_1.MongoshInvalidInputError('Replication not detected. Are you connected to a replset?', error_codes_1.ShellApiErrors.NotConnectedToReplicaSet);
|
|
830
|
-
}
|
|
831
|
-
const ol = localdb.getCollection(oplog);
|
|
832
|
-
const [olStats, first, last] = await Promise.all([
|
|
833
|
-
ol.stats(),
|
|
834
|
-
(async () => (await ol.find()).sort({ $natural: 1 }).limit(1).tryNext())(),
|
|
835
|
-
(async () => (await ol.find()).sort({ $natural: -1 }).limit(1).tryNext())()
|
|
836
|
-
]);
|
|
837
|
-
if (!(olStats === null || olStats === void 0 ? void 0 : olStats.maxSize)) {
|
|
838
|
-
throw new errors_1.MongoshRuntimeError(`Could not get stats for local.${oplog} collection. collstats returned ${JSON.stringify(olStats)}`, errors_1.CommonErrors.CommandFailed);
|
|
839
|
-
}
|
|
840
|
-
result.configuredLogSizeMB = olStats.maxSize / (1024 * 1024);
|
|
841
|
-
result.logSizeMB = Math.max(olStats.maxSize, olStats.size) / (1024 * 1024);
|
|
842
|
-
result.usedMB = olStats.size / (1024 * 1024);
|
|
843
|
-
result.usedMB = Math.ceil(result.usedMB * 100) / 100;
|
|
844
|
-
if (first === null || last === null) {
|
|
845
|
-
throw new errors_1.MongoshRuntimeError('objects not found in local.oplog.$main -- is this a new and empty db instance?', errors_1.CommonErrors.CommandFailed);
|
|
846
|
-
}
|
|
847
|
-
let tfirst = first.ts;
|
|
848
|
-
let tlast = last.ts;
|
|
849
|
-
if (tfirst && tlast) {
|
|
850
|
-
tfirst = (0, helpers_1.tsToSeconds)(tfirst);
|
|
851
|
-
tlast = (0, helpers_1.tsToSeconds)(tlast);
|
|
852
|
-
result.timeDiff = tlast - tfirst;
|
|
853
|
-
result.timeDiffHours = Math.round(result.timeDiff / 36) / 100;
|
|
854
|
-
result.tFirst = (new Date(tfirst * 1000)).toString();
|
|
855
|
-
result.tLast = (new Date(tlast * 1000)).toString();
|
|
856
|
-
result.now = Date();
|
|
857
|
-
}
|
|
858
|
-
else {
|
|
859
|
-
result.errmsg = 'ts element not found in oplog objects';
|
|
860
|
-
}
|
|
861
|
-
return result;
|
|
862
|
-
}
|
|
863
|
-
async printReplicationInfo() {
|
|
864
|
-
const result = {};
|
|
865
|
-
let replInfo;
|
|
866
|
-
try {
|
|
867
|
-
replInfo = await this.getReplicationInfo();
|
|
868
|
-
}
|
|
869
|
-
catch (error) {
|
|
870
|
-
const helloResult = await this.hello();
|
|
871
|
-
if (helloResult.arbiterOnly) {
|
|
872
|
-
return new index_1.CommandResult('StatsResult', { message: 'cannot provide replication status from an arbiter' });
|
|
873
|
-
}
|
|
874
|
-
else if (!helloResult.isWritablePrimary) {
|
|
875
|
-
const secondaryInfo = await this.printSecondaryReplicationInfo();
|
|
876
|
-
return new index_1.CommandResult('StatsResult', {
|
|
877
|
-
message: 'this is a secondary, printing secondary replication info.',
|
|
878
|
-
...secondaryInfo.value
|
|
879
|
-
});
|
|
880
|
-
}
|
|
881
|
-
throw error;
|
|
882
|
-
}
|
|
883
|
-
result['actual oplog size'] = `${replInfo.logSizeMB} MB`;
|
|
884
|
-
result['configured oplog size'] = `${replInfo.configuredLogSizeMB} MB`;
|
|
885
|
-
result['log length start to end'] = `${replInfo.timeDiff} secs (${replInfo.timeDiffHours} hrs)`;
|
|
886
|
-
result['oplog first event time'] = replInfo.tFirst;
|
|
887
|
-
result['oplog last event time'] = replInfo.tLast;
|
|
888
|
-
result.now = replInfo.now;
|
|
889
|
-
return new index_1.CommandResult('StatsResult', result);
|
|
890
|
-
}
|
|
891
|
-
printSlaveReplicationInfo() {
|
|
892
|
-
throw new errors_1.MongoshDeprecatedError('Method deprecated, use db.printSecondaryReplicationInfo instead');
|
|
893
|
-
}
|
|
894
|
-
async setSecondaryOk() {
|
|
895
|
-
await this._mongo.setSecondaryOk();
|
|
896
|
-
}
|
|
897
|
-
async watch(pipeline = [], options = {}) {
|
|
898
|
-
if (!Array.isArray(pipeline)) {
|
|
899
|
-
options = pipeline;
|
|
900
|
-
pipeline = [];
|
|
901
|
-
}
|
|
902
|
-
this._emitDatabaseApiCall('watch', { pipeline, options });
|
|
903
|
-
const cursor = new change_stream_cursor_1.default(this._mongo._serviceProvider.watch(pipeline, {
|
|
904
|
-
...await this._baseOptions(),
|
|
905
|
-
...options
|
|
906
|
-
}, {}, this._name), this._name, this._mongo);
|
|
907
|
-
if (!options.resumeAfter && !options.startAfter && !options.startAtOperationTime) {
|
|
908
|
-
await cursor.tryNext();
|
|
909
|
-
}
|
|
910
|
-
this._mongo._instanceState.currentCursor = cursor;
|
|
911
|
-
return cursor;
|
|
912
|
-
}
|
|
913
|
-
async sql(sqlString, options) {
|
|
914
|
-
var _a;
|
|
915
|
-
this._emitDatabaseApiCall('sql', { sqlString: sqlString, options });
|
|
916
|
-
await this._instanceState.shellApi.print('Note: this is an experimental feature that may be subject to change in future releases.');
|
|
917
|
-
const cursor = await this.aggregate([{
|
|
918
|
-
$sql: {
|
|
919
|
-
statement: sqlString,
|
|
920
|
-
format: 'jdbc',
|
|
921
|
-
dialect: 'mongosql',
|
|
922
|
-
formatVersion: 1
|
|
923
|
-
}
|
|
924
|
-
}], options);
|
|
925
|
-
try {
|
|
926
|
-
await cursor.hasNext();
|
|
927
|
-
}
|
|
928
|
-
catch (err) {
|
|
929
|
-
if (((_a = err.code) === null || _a === void 0 ? void 0 : _a.valueOf()) === 40324) {
|
|
930
|
-
throw new errors_1.MongoshRuntimeError('db.sql currently only works when connected to a Data Lake', errors_1.CommonErrors.CommandFailed);
|
|
931
|
-
}
|
|
932
|
-
throw err;
|
|
933
|
-
}
|
|
934
|
-
return cursor;
|
|
935
|
-
}
|
|
936
|
-
};
|
|
937
|
-
__decorate([
|
|
938
|
-
(0, decorators_1.returnType)('Mongo')
|
|
939
|
-
], Database.prototype, "getMongo", null);
|
|
940
|
-
__decorate([
|
|
941
|
-
decorators_1.returnsPromise,
|
|
942
|
-
(0, decorators_1.apiVersions)([1])
|
|
943
|
-
], Database.prototype, "getCollectionNames", null);
|
|
944
|
-
__decorate([
|
|
945
|
-
decorators_1.returnsPromise,
|
|
946
|
-
(0, decorators_1.serverVersions)(['3.0.0', enums_1.ServerVersions.latest]),
|
|
947
|
-
(0, decorators_1.apiVersions)([1])
|
|
948
|
-
], Database.prototype, "getCollectionInfos", null);
|
|
949
|
-
__decorate([
|
|
950
|
-
decorators_1.returnsPromise,
|
|
951
|
-
(0, decorators_1.apiVersions)([1])
|
|
952
|
-
], Database.prototype, "runCommand", null);
|
|
953
|
-
__decorate([
|
|
954
|
-
decorators_1.returnsPromise,
|
|
955
|
-
(0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest]),
|
|
956
|
-
(0, decorators_1.apiVersions)([1])
|
|
957
|
-
], Database.prototype, "adminCommand", null);
|
|
958
|
-
__decorate([
|
|
959
|
-
decorators_1.returnsPromise,
|
|
960
|
-
(0, decorators_1.returnType)('AggregationCursor'),
|
|
961
|
-
(0, decorators_1.apiVersions)([1])
|
|
962
|
-
], Database.prototype, "aggregate", null);
|
|
963
|
-
__decorate([
|
|
964
|
-
(0, decorators_1.returnType)('Database')
|
|
965
|
-
], Database.prototype, "getSiblingDB", null);
|
|
966
|
-
__decorate([
|
|
967
|
-
(0, decorators_1.returnType)('Collection')
|
|
968
|
-
], Database.prototype, "getCollection", null);
|
|
969
|
-
__decorate([
|
|
970
|
-
decorators_1.returnsPromise,
|
|
971
|
-
(0, decorators_1.apiVersions)([1])
|
|
972
|
-
], Database.prototype, "dropDatabase", null);
|
|
973
|
-
__decorate([
|
|
974
|
-
decorators_1.returnsPromise,
|
|
975
|
-
(0, decorators_1.apiVersions)([])
|
|
976
|
-
], Database.prototype, "createUser", null);
|
|
977
|
-
__decorate([
|
|
978
|
-
decorators_1.returnsPromise
|
|
979
|
-
], Database.prototype, "updateUser", null);
|
|
980
|
-
__decorate([
|
|
981
|
-
decorators_1.returnsPromise,
|
|
982
|
-
(0, decorators_1.apiVersions)([])
|
|
983
|
-
], Database.prototype, "changeUserPassword", null);
|
|
984
|
-
__decorate([
|
|
985
|
-
decorators_1.returnsPromise,
|
|
986
|
-
(0, decorators_1.apiVersions)([])
|
|
987
|
-
], Database.prototype, "logout", null);
|
|
988
|
-
__decorate([
|
|
989
|
-
decorators_1.returnsPromise,
|
|
990
|
-
(0, decorators_1.apiVersions)([])
|
|
991
|
-
], Database.prototype, "dropUser", null);
|
|
992
|
-
__decorate([
|
|
993
|
-
decorators_1.returnsPromise,
|
|
994
|
-
(0, decorators_1.apiVersions)([])
|
|
995
|
-
], Database.prototype, "dropAllUsers", null);
|
|
996
|
-
__decorate([
|
|
997
|
-
decorators_1.returnsPromise
|
|
998
|
-
], Database.prototype, "auth", null);
|
|
999
|
-
__decorate([
|
|
1000
|
-
decorators_1.returnsPromise,
|
|
1001
|
-
(0, decorators_1.apiVersions)([])
|
|
1002
|
-
], Database.prototype, "grantRolesToUser", null);
|
|
1003
|
-
__decorate([
|
|
1004
|
-
decorators_1.returnsPromise,
|
|
1005
|
-
(0, decorators_1.apiVersions)([])
|
|
1006
|
-
], Database.prototype, "revokeRolesFromUser", null);
|
|
1007
|
-
__decorate([
|
|
1008
|
-
decorators_1.returnsPromise,
|
|
1009
|
-
(0, decorators_1.apiVersions)([])
|
|
1010
|
-
], Database.prototype, "getUser", null);
|
|
1011
|
-
__decorate([
|
|
1012
|
-
decorators_1.returnsPromise,
|
|
1013
|
-
(0, decorators_1.apiVersions)([])
|
|
1014
|
-
], Database.prototype, "getUsers", null);
|
|
1015
|
-
__decorate([
|
|
1016
|
-
decorators_1.returnsPromise,
|
|
1017
|
-
(0, decorators_1.apiVersions)([1])
|
|
1018
|
-
], Database.prototype, "createCollection", null);
|
|
1019
|
-
__decorate([
|
|
1020
|
-
decorators_1.returnsPromise,
|
|
1021
|
-
(0, decorators_1.apiVersions)([1])
|
|
1022
|
-
], Database.prototype, "createView", null);
|
|
1023
|
-
__decorate([
|
|
1024
|
-
decorators_1.returnsPromise,
|
|
1025
|
-
(0, decorators_1.apiVersions)([])
|
|
1026
|
-
], Database.prototype, "createRole", null);
|
|
1027
|
-
__decorate([
|
|
1028
|
-
decorators_1.returnsPromise,
|
|
1029
|
-
(0, decorators_1.apiVersions)([])
|
|
1030
|
-
], Database.prototype, "updateRole", null);
|
|
1031
|
-
__decorate([
|
|
1032
|
-
decorators_1.returnsPromise,
|
|
1033
|
-
(0, decorators_1.apiVersions)([])
|
|
1034
|
-
], Database.prototype, "dropRole", null);
|
|
1035
|
-
__decorate([
|
|
1036
|
-
decorators_1.returnsPromise
|
|
1037
|
-
], Database.prototype, "dropAllRoles", null);
|
|
1038
|
-
__decorate([
|
|
1039
|
-
decorators_1.returnsPromise,
|
|
1040
|
-
(0, decorators_1.apiVersions)([])
|
|
1041
|
-
], Database.prototype, "grantRolesToRole", null);
|
|
1042
|
-
__decorate([
|
|
1043
|
-
decorators_1.returnsPromise,
|
|
1044
|
-
(0, decorators_1.apiVersions)([])
|
|
1045
|
-
], Database.prototype, "revokeRolesFromRole", null);
|
|
1046
|
-
__decorate([
|
|
1047
|
-
decorators_1.returnsPromise
|
|
1048
|
-
], Database.prototype, "grantPrivilegesToRole", null);
|
|
1049
|
-
__decorate([
|
|
1050
|
-
decorators_1.returnsPromise,
|
|
1051
|
-
(0, decorators_1.apiVersions)([])
|
|
1052
|
-
], Database.prototype, "revokePrivilegesFromRole", null);
|
|
1053
|
-
__decorate([
|
|
1054
|
-
decorators_1.returnsPromise,
|
|
1055
|
-
(0, decorators_1.apiVersions)([])
|
|
1056
|
-
], Database.prototype, "getRole", null);
|
|
1057
|
-
__decorate([
|
|
1058
|
-
decorators_1.returnsPromise,
|
|
1059
|
-
(0, decorators_1.apiVersions)([])
|
|
1060
|
-
], Database.prototype, "getRoles", null);
|
|
1061
|
-
__decorate([
|
|
1062
|
-
decorators_1.returnsPromise,
|
|
1063
|
-
(0, decorators_1.apiVersions)([])
|
|
1064
|
-
], Database.prototype, "currentOp", null);
|
|
1065
|
-
__decorate([
|
|
1066
|
-
decorators_1.returnsPromise,
|
|
1067
|
-
(0, decorators_1.apiVersions)([])
|
|
1068
|
-
], Database.prototype, "killOp", null);
|
|
1069
|
-
__decorate([
|
|
1070
|
-
decorators_1.returnsPromise,
|
|
1071
|
-
(0, decorators_1.apiVersions)([])
|
|
1072
|
-
], Database.prototype, "shutdownServer", null);
|
|
1073
|
-
__decorate([
|
|
1074
|
-
decorators_1.returnsPromise,
|
|
1075
|
-
(0, decorators_1.apiVersions)([])
|
|
1076
|
-
], Database.prototype, "fsyncLock", null);
|
|
1077
|
-
__decorate([
|
|
1078
|
-
decorators_1.returnsPromise,
|
|
1079
|
-
(0, decorators_1.apiVersions)([])
|
|
1080
|
-
], Database.prototype, "fsyncUnlock", null);
|
|
1081
|
-
__decorate([
|
|
1082
|
-
decorators_1.returnsPromise,
|
|
1083
|
-
(0, decorators_1.apiVersions)([])
|
|
1084
|
-
], Database.prototype, "version", null);
|
|
1085
|
-
__decorate([
|
|
1086
|
-
decorators_1.returnsPromise,
|
|
1087
|
-
(0, decorators_1.apiVersions)([])
|
|
1088
|
-
], Database.prototype, "serverBits", null);
|
|
1089
|
-
__decorate([
|
|
1090
|
-
decorators_1.returnsPromise,
|
|
1091
|
-
(0, decorators_1.apiVersions)([])
|
|
1092
|
-
], Database.prototype, "isMaster", null);
|
|
1093
|
-
__decorate([
|
|
1094
|
-
decorators_1.returnsPromise,
|
|
1095
|
-
(0, decorators_1.apiVersions)([1]),
|
|
1096
|
-
(0, decorators_1.serverVersions)(['5.0.0', enums_1.ServerVersions.latest])
|
|
1097
|
-
], Database.prototype, "hello", null);
|
|
1098
|
-
__decorate([
|
|
1099
|
-
decorators_1.returnsPromise,
|
|
1100
|
-
(0, decorators_1.apiVersions)([])
|
|
1101
|
-
], Database.prototype, "serverBuildInfo", null);
|
|
1102
|
-
__decorate([
|
|
1103
|
-
decorators_1.returnsPromise,
|
|
1104
|
-
(0, decorators_1.apiVersions)([])
|
|
1105
|
-
], Database.prototype, "serverStatus", null);
|
|
1106
|
-
__decorate([
|
|
1107
|
-
decorators_1.returnsPromise,
|
|
1108
|
-
(0, decorators_1.apiVersions)([])
|
|
1109
|
-
], Database.prototype, "stats", null);
|
|
1110
|
-
__decorate([
|
|
1111
|
-
decorators_1.returnsPromise,
|
|
1112
|
-
(0, decorators_1.apiVersions)([])
|
|
1113
|
-
], Database.prototype, "hostInfo", null);
|
|
1114
|
-
__decorate([
|
|
1115
|
-
decorators_1.returnsPromise,
|
|
1116
|
-
(0, decorators_1.apiVersions)([])
|
|
1117
|
-
], Database.prototype, "serverCmdLineOpts", null);
|
|
1118
|
-
__decorate([
|
|
1119
|
-
decorators_1.returnsPromise,
|
|
1120
|
-
(0, decorators_1.serverVersions)(['5.0.0', enums_1.ServerVersions.latest]),
|
|
1121
|
-
(0, decorators_1.apiVersions)([])
|
|
1122
|
-
], Database.prototype, "rotateCertificates", null);
|
|
1123
|
-
__decorate([
|
|
1124
|
-
decorators_1.returnsPromise,
|
|
1125
|
-
(0, decorators_1.apiVersions)([])
|
|
1126
|
-
], Database.prototype, "printCollectionStats", null);
|
|
1127
|
-
__decorate([
|
|
1128
|
-
decorators_1.returnsPromise,
|
|
1129
|
-
(0, decorators_1.apiVersions)([])
|
|
1130
|
-
], Database.prototype, "getFreeMonitoringStatus", null);
|
|
1131
|
-
__decorate([
|
|
1132
|
-
decorators_1.returnsPromise,
|
|
1133
|
-
(0, decorators_1.apiVersions)([])
|
|
1134
|
-
], Database.prototype, "disableFreeMonitoring", null);
|
|
1135
|
-
__decorate([
|
|
1136
|
-
decorators_1.returnsPromise,
|
|
1137
|
-
(0, decorators_1.apiVersions)([])
|
|
1138
|
-
], Database.prototype, "enableFreeMonitoring", null);
|
|
1139
|
-
__decorate([
|
|
1140
|
-
decorators_1.returnsPromise,
|
|
1141
|
-
(0, decorators_1.apiVersions)([])
|
|
1142
|
-
], Database.prototype, "getProfilingStatus", null);
|
|
1143
|
-
__decorate([
|
|
1144
|
-
decorators_1.returnsPromise,
|
|
1145
|
-
(0, decorators_1.apiVersions)([])
|
|
1146
|
-
], Database.prototype, "setProfilingLevel", null);
|
|
1147
|
-
__decorate([
|
|
1148
|
-
decorators_1.returnsPromise,
|
|
1149
|
-
(0, decorators_1.apiVersions)([])
|
|
1150
|
-
], Database.prototype, "setLogLevel", null);
|
|
1151
|
-
__decorate([
|
|
1152
|
-
decorators_1.returnsPromise,
|
|
1153
|
-
(0, decorators_1.apiVersions)([])
|
|
1154
|
-
], Database.prototype, "getLogComponents", null);
|
|
1155
|
-
__decorate([
|
|
1156
|
-
decorators_1.deprecated
|
|
1157
|
-
], Database.prototype, "cloneDatabase", null);
|
|
1158
|
-
__decorate([
|
|
1159
|
-
decorators_1.deprecated
|
|
1160
|
-
], Database.prototype, "cloneCollection", null);
|
|
1161
|
-
__decorate([
|
|
1162
|
-
decorators_1.deprecated
|
|
1163
|
-
], Database.prototype, "copyDatabase", null);
|
|
1164
|
-
__decorate([
|
|
1165
|
-
decorators_1.returnsPromise,
|
|
1166
|
-
(0, decorators_1.apiVersions)([1])
|
|
1167
|
-
], Database.prototype, "commandHelp", null);
|
|
1168
|
-
__decorate([
|
|
1169
|
-
decorators_1.returnsPromise,
|
|
1170
|
-
(0, decorators_1.apiVersions)([])
|
|
1171
|
-
], Database.prototype, "listCommands", null);
|
|
1172
|
-
__decorate([
|
|
1173
|
-
decorators_1.deprecated,
|
|
1174
|
-
decorators_1.returnsPromise,
|
|
1175
|
-
(0, decorators_1.apiVersions)([])
|
|
1176
|
-
], Database.prototype, "getLastErrorObj", null);
|
|
1177
|
-
__decorate([
|
|
1178
|
-
decorators_1.deprecated,
|
|
1179
|
-
decorators_1.returnsPromise,
|
|
1180
|
-
(0, decorators_1.apiVersions)([])
|
|
1181
|
-
], Database.prototype, "getLastError", null);
|
|
1182
|
-
__decorate([
|
|
1183
|
-
decorators_1.returnsPromise,
|
|
1184
|
-
(0, decorators_1.topologies)([enums_1.Topologies.Sharded]),
|
|
1185
|
-
(0, decorators_1.apiVersions)([1])
|
|
1186
|
-
], Database.prototype, "printShardingStatus", null);
|
|
1187
|
-
__decorate([
|
|
1188
|
-
decorators_1.returnsPromise,
|
|
1189
|
-
(0, decorators_1.topologies)([enums_1.Topologies.ReplSet]),
|
|
1190
|
-
(0, decorators_1.apiVersions)([])
|
|
1191
|
-
], Database.prototype, "printSecondaryReplicationInfo", null);
|
|
1192
|
-
__decorate([
|
|
1193
|
-
decorators_1.returnsPromise,
|
|
1194
|
-
(0, decorators_1.topologies)([enums_1.Topologies.ReplSet]),
|
|
1195
|
-
(0, decorators_1.apiVersions)([])
|
|
1196
|
-
], Database.prototype, "getReplicationInfo", null);
|
|
1197
|
-
__decorate([
|
|
1198
|
-
decorators_1.returnsPromise,
|
|
1199
|
-
(0, decorators_1.apiVersions)([]),
|
|
1200
|
-
(0, decorators_1.topologies)([enums_1.Topologies.ReplSet])
|
|
1201
|
-
], Database.prototype, "printReplicationInfo", null);
|
|
1202
|
-
__decorate([
|
|
1203
|
-
decorators_1.deprecated
|
|
1204
|
-
], Database.prototype, "printSlaveReplicationInfo", null);
|
|
1205
|
-
__decorate([
|
|
1206
|
-
decorators_1.deprecated,
|
|
1207
|
-
decorators_1.returnsPromise
|
|
1208
|
-
], Database.prototype, "setSecondaryOk", null);
|
|
1209
|
-
__decorate([
|
|
1210
|
-
(0, decorators_1.serverVersions)(['3.1.0', enums_1.ServerVersions.latest]),
|
|
1211
|
-
(0, decorators_1.topologies)([enums_1.Topologies.ReplSet, enums_1.Topologies.Sharded]),
|
|
1212
|
-
(0, decorators_1.apiVersions)([1]),
|
|
1213
|
-
decorators_1.returnsPromise
|
|
1214
|
-
], Database.prototype, "watch", null);
|
|
1215
|
-
__decorate([
|
|
1216
|
-
(0, decorators_1.serverVersions)(['4.4.0', enums_1.ServerVersions.latest]),
|
|
1217
|
-
decorators_1.returnsPromise,
|
|
1218
|
-
(0, decorators_1.returnType)('AggregationCursor')
|
|
1219
|
-
], Database.prototype, "sql", null);
|
|
1220
|
-
Database = __decorate([
|
|
1221
|
-
decorators_1.shellApiClassDefault
|
|
1222
|
-
], Database);
|
|
1223
|
-
exports.default = Database;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const collection_1 = __importDefault(require("./collection"));
|
|
13
|
+
const decorators_1 = require("./decorators");
|
|
14
|
+
const enums_1 = require("./enums");
|
|
15
|
+
const helpers_1 = require("./helpers");
|
|
16
|
+
const index_1 = require("./index");
|
|
17
|
+
const errors_1 = require("@qp-mongosh/errors");
|
|
18
|
+
const history_1 = require("@qp-mongosh/history");
|
|
19
|
+
const change_stream_cursor_1 = __importDefault(require("./change-stream-cursor"));
|
|
20
|
+
const error_codes_1 = require("./error-codes");
|
|
21
|
+
let Database = class Database extends decorators_1.ShellApiWithMongoClass {
|
|
22
|
+
constructor(mongo, name, session) {
|
|
23
|
+
super();
|
|
24
|
+
this._cachedCollectionNames = [];
|
|
25
|
+
this._cachedHello = null;
|
|
26
|
+
this._mongo = mongo;
|
|
27
|
+
this._name = name;
|
|
28
|
+
const collections = {};
|
|
29
|
+
this._collections = collections;
|
|
30
|
+
this._session = session;
|
|
31
|
+
const proxy = new Proxy(this, {
|
|
32
|
+
get: (target, prop) => {
|
|
33
|
+
if (prop in target) {
|
|
34
|
+
return target[prop];
|
|
35
|
+
}
|
|
36
|
+
if (typeof prop !== 'string' ||
|
|
37
|
+
prop.startsWith('_') ||
|
|
38
|
+
!(0, helpers_1.isValidCollectionName)(prop)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (!collections[prop]) {
|
|
42
|
+
collections[prop] = new collection_1.default(mongo, proxy, prop);
|
|
43
|
+
}
|
|
44
|
+
return collections[prop];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return proxy;
|
|
48
|
+
}
|
|
49
|
+
async _baseOptions() {
|
|
50
|
+
const options = {};
|
|
51
|
+
if (this._session) {
|
|
52
|
+
options.session = this._session._session;
|
|
53
|
+
}
|
|
54
|
+
const maxTimeMS = await this._instanceState.shellApi.config.get('maxTimeMS');
|
|
55
|
+
if (typeof maxTimeMS === 'number') {
|
|
56
|
+
options.maxTimeMS = maxTimeMS;
|
|
57
|
+
}
|
|
58
|
+
return options;
|
|
59
|
+
}
|
|
60
|
+
async _maybeCachedHello() {
|
|
61
|
+
var _a;
|
|
62
|
+
return (_a = this._cachedHello) !== null && _a !== void 0 ? _a : await this.hello();
|
|
63
|
+
}
|
|
64
|
+
[enums_1.asPrintable]() {
|
|
65
|
+
return this._name;
|
|
66
|
+
}
|
|
67
|
+
_emitDatabaseApiCall(methodName, methodArguments = {}) {
|
|
68
|
+
this._mongo._instanceState.emitApiCallWithArgs({
|
|
69
|
+
method: methodName,
|
|
70
|
+
class: 'Database',
|
|
71
|
+
db: this._name,
|
|
72
|
+
arguments: methodArguments
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async _runCommand(cmd, options = {}) {
|
|
76
|
+
return this._mongo._serviceProvider.runCommandWithCheck(this._name, (0, helpers_1.adjustRunCommand)(cmd, this._instanceState.shellBson), { ...this._mongo._getExplicitlyRequestedReadPref(), ...await this._baseOptions(), ...options });
|
|
77
|
+
}
|
|
78
|
+
async _runAdminCommand(cmd, options = {}) {
|
|
79
|
+
return this.getSiblingDB('admin')._runCommand(cmd, { ...await this._baseOptions(), ...options });
|
|
80
|
+
}
|
|
81
|
+
async _listCollections(filter, options) {
|
|
82
|
+
return await this._mongo._serviceProvider.listCollections(this._name, filter, { ...this._mongo._getExplicitlyRequestedReadPref(), ...await this._baseOptions(), ...options }) || [];
|
|
83
|
+
}
|
|
84
|
+
async _getCollectionNames(options) {
|
|
85
|
+
const infos = await this._listCollections({}, { ...options, nameOnly: true });
|
|
86
|
+
this._cachedCollectionNames = infos.map((collection) => collection.name);
|
|
87
|
+
return this._cachedCollectionNames;
|
|
88
|
+
}
|
|
89
|
+
async _getCollectionNamesWithTypes(options) {
|
|
90
|
+
let collections = await this._listCollections({}, { ...options, nameOnly: true });
|
|
91
|
+
collections = collections.sort((c1, c2) => (c1.name).localeCompare(c2.name));
|
|
92
|
+
const typesToBages = {
|
|
93
|
+
timeseries: '[time-series]',
|
|
94
|
+
view: '[view]'
|
|
95
|
+
};
|
|
96
|
+
this._cachedCollectionNames = collections.map((collection) => collection.name);
|
|
97
|
+
return collections.map((collection) => {
|
|
98
|
+
var _a;
|
|
99
|
+
return ({
|
|
100
|
+
name: collection.name,
|
|
101
|
+
badge: (_a = typesToBages[collection.type]) !== null && _a !== void 0 ? _a : ''
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
async _getCollectionNamesForCompletion() {
|
|
106
|
+
return await Promise.race([
|
|
107
|
+
(async () => {
|
|
108
|
+
return await this._getCollectionNames({ readPreference: 'primaryPreferred' });
|
|
109
|
+
})(),
|
|
110
|
+
(async () => {
|
|
111
|
+
await new Promise(resolve => setTimeout(resolve, 200).unref());
|
|
112
|
+
return this._cachedCollectionNames;
|
|
113
|
+
})()
|
|
114
|
+
]);
|
|
115
|
+
}
|
|
116
|
+
async _getLastErrorObj(w, wTimeout, j) {
|
|
117
|
+
const cmd = { getlasterror: 1 };
|
|
118
|
+
if (w) {
|
|
119
|
+
cmd.w = w;
|
|
120
|
+
}
|
|
121
|
+
if (wTimeout) {
|
|
122
|
+
cmd.wtimeout = wTimeout;
|
|
123
|
+
}
|
|
124
|
+
if (j !== undefined) {
|
|
125
|
+
cmd.j = j;
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
return await this._mongo._serviceProvider.runCommand(this._name, cmd, await this._baseOptions());
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
return e;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
getMongo() {
|
|
135
|
+
return this._mongo;
|
|
136
|
+
}
|
|
137
|
+
getName() {
|
|
138
|
+
return this._name;
|
|
139
|
+
}
|
|
140
|
+
async getCollectionNames() {
|
|
141
|
+
this._emitDatabaseApiCall('getCollectionNames');
|
|
142
|
+
return this._getCollectionNames();
|
|
143
|
+
}
|
|
144
|
+
async getCollectionInfos(filter = {}, options = {}) {
|
|
145
|
+
this._emitDatabaseApiCall('getCollectionInfos', { filter, options });
|
|
146
|
+
return await this._listCollections(filter, options);
|
|
147
|
+
}
|
|
148
|
+
async runCommand(cmd) {
|
|
149
|
+
(0, helpers_1.assertArgsDefinedType)([cmd], [['string', 'object']], 'Database.runCommand');
|
|
150
|
+
if (typeof cmd === 'string') {
|
|
151
|
+
cmd = { [cmd]: 1 };
|
|
152
|
+
}
|
|
153
|
+
const hiddenCommands = new RegExp(history_1.HIDDEN_COMMANDS);
|
|
154
|
+
if (!Object.keys(cmd).some(k => hiddenCommands.test(k))) {
|
|
155
|
+
this._emitDatabaseApiCall('runCommand', { cmd });
|
|
156
|
+
}
|
|
157
|
+
return this._runCommand(cmd);
|
|
158
|
+
}
|
|
159
|
+
async adminCommand(cmd) {
|
|
160
|
+
(0, helpers_1.assertArgsDefinedType)([cmd], [['string', 'object']], 'Database.adminCommand');
|
|
161
|
+
if (typeof cmd === 'string') {
|
|
162
|
+
cmd = { [cmd]: 1 };
|
|
163
|
+
}
|
|
164
|
+
const hiddenCommands = new RegExp(history_1.HIDDEN_COMMANDS);
|
|
165
|
+
if (!Object.keys(cmd).some(k => hiddenCommands.test(k))) {
|
|
166
|
+
this._emitDatabaseApiCall('adminCommand', { cmd });
|
|
167
|
+
}
|
|
168
|
+
return await this._runAdminCommand(cmd, {});
|
|
169
|
+
}
|
|
170
|
+
async aggregate(pipeline, options) {
|
|
171
|
+
(0, helpers_1.assertArgsDefinedType)([pipeline], [true], 'Database.aggregate');
|
|
172
|
+
this._emitDatabaseApiCall('aggregate', { options, pipeline });
|
|
173
|
+
const { aggOptions, dbOptions, explain } = (0, helpers_1.adaptAggregateOptions)(options);
|
|
174
|
+
const providerCursor = this._mongo._serviceProvider.aggregateDb(this._name, pipeline, { ...await this._baseOptions(), ...aggOptions }, dbOptions);
|
|
175
|
+
const cursor = new index_1.AggregationCursor(this._mongo, providerCursor);
|
|
176
|
+
if (explain) {
|
|
177
|
+
return await cursor.explain(explain);
|
|
178
|
+
}
|
|
179
|
+
else if ((0, helpers_1.shouldRunAggregationImmediately)(pipeline)) {
|
|
180
|
+
await cursor.hasNext();
|
|
181
|
+
}
|
|
182
|
+
this._mongo._instanceState.currentCursor = cursor;
|
|
183
|
+
return cursor;
|
|
184
|
+
}
|
|
185
|
+
getSiblingDB(db) {
|
|
186
|
+
(0, helpers_1.assertArgsDefinedType)([db], ['string'], 'Database.getSiblingDB');
|
|
187
|
+
this._emitDatabaseApiCall('getSiblingDB', { db });
|
|
188
|
+
if (this._session) {
|
|
189
|
+
return this._session.getDatabase(db);
|
|
190
|
+
}
|
|
191
|
+
return this._mongo._getDb(db);
|
|
192
|
+
}
|
|
193
|
+
getCollection(coll) {
|
|
194
|
+
(0, helpers_1.assertArgsDefinedType)([coll], ['string'], 'Database.getColl');
|
|
195
|
+
this._emitDatabaseApiCall('getCollection', { coll });
|
|
196
|
+
if (!(0, helpers_1.isValidCollectionName)(coll)) {
|
|
197
|
+
throw new errors_1.MongoshInvalidInputError(`Invalid collection name: ${coll}`, errors_1.CommonErrors.InvalidArgument);
|
|
198
|
+
}
|
|
199
|
+
const collections = this._collections;
|
|
200
|
+
if (!collections[coll]) {
|
|
201
|
+
collections[coll] = new collection_1.default(this._mongo, this, coll);
|
|
202
|
+
}
|
|
203
|
+
return collections[coll];
|
|
204
|
+
}
|
|
205
|
+
async dropDatabase(writeConcern) {
|
|
206
|
+
return await this._mongo._serviceProvider.dropDatabase(this._name, { ...await this._baseOptions(), writeConcern });
|
|
207
|
+
}
|
|
208
|
+
async createUser(user, writeConcern) {
|
|
209
|
+
(0, helpers_1.assertArgsDefinedType)([user], ['object'], 'Database.createUser');
|
|
210
|
+
(0, helpers_1.assertKeysDefined)(user, ['user', 'roles']);
|
|
211
|
+
if (this._name === '$external') {
|
|
212
|
+
if ('pwd' in user) {
|
|
213
|
+
throw new errors_1.MongoshInvalidInputError('Cannot set password for users on the $external database', errors_1.CommonErrors.InvalidArgument);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
(0, helpers_1.assertKeysDefined)(user, ['pwd']);
|
|
218
|
+
}
|
|
219
|
+
this._emitDatabaseApiCall('createUser', {});
|
|
220
|
+
if (user.createUser) {
|
|
221
|
+
throw new errors_1.MongoshInvalidInputError('Cannot set createUser field in helper method', errors_1.CommonErrors.InvalidArgument);
|
|
222
|
+
}
|
|
223
|
+
const command = (0, helpers_1.adaptOptions)({ user: 'createUser', passwordDigestor: null }, {}, user);
|
|
224
|
+
if (writeConcern) {
|
|
225
|
+
command.writeConcern = writeConcern;
|
|
226
|
+
}
|
|
227
|
+
const digestPwd = (0, helpers_1.processDigestPassword)(user.user, user.passwordDigestor, command);
|
|
228
|
+
const orderedCmd = { createUser: command.createUser, ...command, ...digestPwd };
|
|
229
|
+
return await this._runCommand(orderedCmd);
|
|
230
|
+
}
|
|
231
|
+
async updateUser(username, userDoc, writeConcern) {
|
|
232
|
+
(0, helpers_1.assertArgsDefinedType)([username, userDoc], ['string', 'object'], 'Database.updateUser');
|
|
233
|
+
this._emitDatabaseApiCall('updateUser', {});
|
|
234
|
+
if (userDoc.passwordDigestor && userDoc.passwordDigestor !== 'server' && userDoc.passwordDigestor !== 'client') {
|
|
235
|
+
throw new errors_1.MongoshInvalidInputError(`Invalid field: passwordDigestor must be 'client' or 'server', got ${userDoc.passwordDigestor}`, errors_1.CommonErrors.InvalidArgument);
|
|
236
|
+
}
|
|
237
|
+
const command = (0, helpers_1.adaptOptions)({ passwordDigestor: null }, {
|
|
238
|
+
updateUser: username
|
|
239
|
+
}, userDoc);
|
|
240
|
+
if (writeConcern) {
|
|
241
|
+
command.writeConcern = writeConcern;
|
|
242
|
+
}
|
|
243
|
+
const digestPwd = (0, helpers_1.processDigestPassword)(username, userDoc.passwordDigestor, command);
|
|
244
|
+
const orderedCmd = { updateUser: command.updateUser, ...command, ...digestPwd };
|
|
245
|
+
return await this._runCommand(orderedCmd);
|
|
246
|
+
}
|
|
247
|
+
async changeUserPassword(username, password, writeConcern) {
|
|
248
|
+
(0, helpers_1.assertArgsDefinedType)([username, password], ['string', 'string'], 'Database.changeUserPassword');
|
|
249
|
+
this._emitDatabaseApiCall('changeUserPassword', {});
|
|
250
|
+
const command = (0, helpers_1.adaptOptions)({}, {
|
|
251
|
+
updateUser: username,
|
|
252
|
+
pwd: password
|
|
253
|
+
}, {});
|
|
254
|
+
if (writeConcern) {
|
|
255
|
+
command.writeConcern = writeConcern;
|
|
256
|
+
}
|
|
257
|
+
const orderedCmd = { updateUser: command.updateUser, ...command };
|
|
258
|
+
return await this._runCommand(orderedCmd);
|
|
259
|
+
}
|
|
260
|
+
async logout() {
|
|
261
|
+
this._emitDatabaseApiCall('logout', {});
|
|
262
|
+
this._mongo._instanceState.currentCursor = null;
|
|
263
|
+
return await this._runCommand({ logout: 1 });
|
|
264
|
+
}
|
|
265
|
+
async dropUser(username, writeConcern) {
|
|
266
|
+
(0, helpers_1.assertArgsDefinedType)([username], ['string'], 'Database.dropUser');
|
|
267
|
+
this._emitDatabaseApiCall('dropUser', {});
|
|
268
|
+
const cmd = { dropUser: username };
|
|
269
|
+
if (writeConcern) {
|
|
270
|
+
cmd.writeConcern = writeConcern;
|
|
271
|
+
}
|
|
272
|
+
return await this._runCommand(cmd);
|
|
273
|
+
}
|
|
274
|
+
async dropAllUsers(writeConcern) {
|
|
275
|
+
this._emitDatabaseApiCall('dropAllUsers', {});
|
|
276
|
+
const cmd = { dropAllUsersFromDatabase: 1 };
|
|
277
|
+
if (writeConcern) {
|
|
278
|
+
cmd.writeConcern = writeConcern;
|
|
279
|
+
}
|
|
280
|
+
return await this._runCommand(cmd);
|
|
281
|
+
}
|
|
282
|
+
async auth(...args) {
|
|
283
|
+
this._emitDatabaseApiCall('auth', {});
|
|
284
|
+
let authDoc;
|
|
285
|
+
if (args.length === 1) {
|
|
286
|
+
const { evaluationListener } = this._mongo._instanceState;
|
|
287
|
+
if (typeof args[0] === 'string' && evaluationListener.onPrompt) {
|
|
288
|
+
authDoc = {
|
|
289
|
+
user: args[0],
|
|
290
|
+
pwd: await evaluationListener.onPrompt('Enter password', 'password')
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
authDoc = args[0];
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
else if (args.length === 2) {
|
|
298
|
+
authDoc = {
|
|
299
|
+
user: args[0],
|
|
300
|
+
pwd: args[1]
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
throw new errors_1.MongoshInvalidInputError('auth expects (username), (username, password), or ({ user: username, pwd: password })', errors_1.CommonErrors.InvalidArgument);
|
|
305
|
+
}
|
|
306
|
+
if ((!authDoc.user || !authDoc.pwd) && !authDoc.mechanism) {
|
|
307
|
+
throw new errors_1.MongoshInvalidInputError('auth expects user document with at least \'user\' and \'pwd\' or \'mechanism\' fields', errors_1.CommonErrors.InvalidArgument);
|
|
308
|
+
}
|
|
309
|
+
if ('digestPassword' in authDoc) {
|
|
310
|
+
throw new errors_1.MongoshUnimplementedError('digestPassword is not supported for authentication.', errors_1.CommonErrors.NotImplemented);
|
|
311
|
+
}
|
|
312
|
+
authDoc.authDb = this._name;
|
|
313
|
+
this._mongo._instanceState.currentCursor = null;
|
|
314
|
+
return await this._mongo._serviceProvider.authenticate(authDoc);
|
|
315
|
+
}
|
|
316
|
+
async grantRolesToUser(username, roles, writeConcern) {
|
|
317
|
+
(0, helpers_1.assertArgsDefinedType)([username, roles], ['string', true], 'Database.grantRolesToUser');
|
|
318
|
+
this._emitDatabaseApiCall('grantRolesToUser', {});
|
|
319
|
+
const cmd = { grantRolesToUser: username, roles: roles };
|
|
320
|
+
if (writeConcern) {
|
|
321
|
+
cmd.writeConcern = writeConcern;
|
|
322
|
+
}
|
|
323
|
+
return await this._runCommand(cmd);
|
|
324
|
+
}
|
|
325
|
+
async revokeRolesFromUser(username, roles, writeConcern) {
|
|
326
|
+
(0, helpers_1.assertArgsDefinedType)([username, roles], ['string', true], 'Database.revokeRolesFromUser');
|
|
327
|
+
this._emitDatabaseApiCall('revokeRolesFromUser', {});
|
|
328
|
+
const cmd = { revokeRolesFromUser: username, roles: roles };
|
|
329
|
+
if (writeConcern) {
|
|
330
|
+
cmd.writeConcern = writeConcern;
|
|
331
|
+
}
|
|
332
|
+
return await this._runCommand(cmd);
|
|
333
|
+
}
|
|
334
|
+
async getUser(username, options = {}) {
|
|
335
|
+
(0, helpers_1.assertArgsDefinedType)([username], ['string'], 'Database.getUser');
|
|
336
|
+
this._emitDatabaseApiCall('getUser', { username: username });
|
|
337
|
+
const command = (0, helpers_1.adaptOptions)({}, { usersInfo: { user: username, db: this._name } }, options);
|
|
338
|
+
const result = await this._runCommand(command);
|
|
339
|
+
if (result.users === undefined) {
|
|
340
|
+
throw new errors_1.MongoshInternalError('No users were returned from the userInfo command');
|
|
341
|
+
}
|
|
342
|
+
for (let i = 0; i < result.users.length; i++) {
|
|
343
|
+
if (result.users[i].user === username) {
|
|
344
|
+
return result.users[i];
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return null;
|
|
348
|
+
}
|
|
349
|
+
async getUsers(options = {}) {
|
|
350
|
+
this._emitDatabaseApiCall('getUsers', { options: options });
|
|
351
|
+
const command = (0, helpers_1.adaptOptions)({}, { usersInfo: 1 }, options);
|
|
352
|
+
return await this._runCommand(command);
|
|
353
|
+
}
|
|
354
|
+
async createCollection(name, options = {}) {
|
|
355
|
+
(0, helpers_1.assertArgsDefinedType)([name], ['string'], 'Database.createCollection');
|
|
356
|
+
this._emitDatabaseApiCall('createCollection', { name: name, options: options });
|
|
357
|
+
return await this._mongo._serviceProvider.createCollection(this._name, name, { ...await this._baseOptions(), ...options });
|
|
358
|
+
}
|
|
359
|
+
async createView(name, source, pipeline, options = {}) {
|
|
360
|
+
(0, helpers_1.assertArgsDefinedType)([name, source, pipeline], ['string', 'string', true], 'Database.createView');
|
|
361
|
+
this._emitDatabaseApiCall('createView', { name, source, pipeline, options });
|
|
362
|
+
const ccOpts = {
|
|
363
|
+
...await this._baseOptions(),
|
|
364
|
+
viewOn: source,
|
|
365
|
+
pipeline: pipeline
|
|
366
|
+
};
|
|
367
|
+
if (options.collation) {
|
|
368
|
+
ccOpts.collation = options.collation;
|
|
369
|
+
}
|
|
370
|
+
return await this._mongo._serviceProvider.createCollection(this._name, name, ccOpts);
|
|
371
|
+
}
|
|
372
|
+
async createRole(role, writeConcern) {
|
|
373
|
+
(0, helpers_1.assertArgsDefinedType)([role], ['object'], 'Database.createRole');
|
|
374
|
+
(0, helpers_1.assertKeysDefined)(role, ['role', 'privileges', 'roles']);
|
|
375
|
+
this._emitDatabaseApiCall('createRole', {});
|
|
376
|
+
if (role.createRole) {
|
|
377
|
+
throw new errors_1.MongoshInvalidInputError('Cannot set createRole field in helper method', errors_1.CommonErrors.InvalidArgument);
|
|
378
|
+
}
|
|
379
|
+
const command = (0, helpers_1.adaptOptions)({ role: 'createRole' }, {}, role);
|
|
380
|
+
if (writeConcern) {
|
|
381
|
+
command.writeConcern = writeConcern;
|
|
382
|
+
}
|
|
383
|
+
const orderedCmd = { createRole: command.createRole, ...command };
|
|
384
|
+
return await this._runCommand(orderedCmd);
|
|
385
|
+
}
|
|
386
|
+
async updateRole(rolename, roleDoc, writeConcern) {
|
|
387
|
+
(0, helpers_1.assertArgsDefinedType)([rolename, roleDoc], ['string', 'object'], 'Database.updateRole');
|
|
388
|
+
this._emitDatabaseApiCall('updateRole', {});
|
|
389
|
+
const command = (0, helpers_1.adaptOptions)({}, {
|
|
390
|
+
updateRole: rolename
|
|
391
|
+
}, roleDoc);
|
|
392
|
+
if (writeConcern) {
|
|
393
|
+
command.writeConcern = writeConcern;
|
|
394
|
+
}
|
|
395
|
+
const orderedCmd = { updateRole: command.updateRole, ...command };
|
|
396
|
+
return await this._runCommand(orderedCmd);
|
|
397
|
+
}
|
|
398
|
+
async dropRole(rolename, writeConcern) {
|
|
399
|
+
(0, helpers_1.assertArgsDefinedType)([rolename], ['string'], 'Database.dropRole');
|
|
400
|
+
this._emitDatabaseApiCall('dropRole', {});
|
|
401
|
+
const cmd = { dropRole: rolename };
|
|
402
|
+
if (writeConcern) {
|
|
403
|
+
cmd.writeConcern = writeConcern;
|
|
404
|
+
}
|
|
405
|
+
return await this._runCommand(cmd);
|
|
406
|
+
}
|
|
407
|
+
async dropAllRoles(writeConcern) {
|
|
408
|
+
this._emitDatabaseApiCall('dropAllRoles', {});
|
|
409
|
+
const cmd = { dropAllRolesFromDatabase: 1 };
|
|
410
|
+
if (writeConcern) {
|
|
411
|
+
cmd.writeConcern = writeConcern;
|
|
412
|
+
}
|
|
413
|
+
return await this._runCommand(cmd);
|
|
414
|
+
}
|
|
415
|
+
async grantRolesToRole(rolename, roles, writeConcern) {
|
|
416
|
+
(0, helpers_1.assertArgsDefinedType)([rolename, roles], ['string', true], 'Database.grantRolesToRole');
|
|
417
|
+
this._emitDatabaseApiCall('grantRolesToRole', {});
|
|
418
|
+
const cmd = { grantRolesToRole: rolename, roles: roles };
|
|
419
|
+
if (writeConcern) {
|
|
420
|
+
cmd.writeConcern = writeConcern;
|
|
421
|
+
}
|
|
422
|
+
return await this._runCommand(cmd);
|
|
423
|
+
}
|
|
424
|
+
async revokeRolesFromRole(rolename, roles, writeConcern) {
|
|
425
|
+
(0, helpers_1.assertArgsDefinedType)([rolename, roles], ['string', true], 'Database.revokeRolesFromRole');
|
|
426
|
+
this._emitDatabaseApiCall('revokeRolesFromRole', {});
|
|
427
|
+
const cmd = { revokeRolesFromRole: rolename, roles: roles };
|
|
428
|
+
if (writeConcern) {
|
|
429
|
+
cmd.writeConcern = writeConcern;
|
|
430
|
+
}
|
|
431
|
+
return await this._runCommand(cmd);
|
|
432
|
+
}
|
|
433
|
+
async grantPrivilegesToRole(rolename, privileges, writeConcern) {
|
|
434
|
+
(0, helpers_1.assertArgsDefinedType)([rolename, privileges], ['string', true], 'Database.grantPrivilegesToRole');
|
|
435
|
+
this._emitDatabaseApiCall('grantPrivilegesToRole', {});
|
|
436
|
+
const cmd = { grantPrivilegesToRole: rolename, privileges: privileges };
|
|
437
|
+
if (writeConcern) {
|
|
438
|
+
cmd.writeConcern = writeConcern;
|
|
439
|
+
}
|
|
440
|
+
return await this._runCommand(cmd);
|
|
441
|
+
}
|
|
442
|
+
async revokePrivilegesFromRole(rolename, privileges, writeConcern) {
|
|
443
|
+
(0, helpers_1.assertArgsDefinedType)([rolename, privileges], ['string', true], 'Database.revokePrivilegesFromRole');
|
|
444
|
+
this._emitDatabaseApiCall('revokePrivilegesFromRole', {});
|
|
445
|
+
const cmd = { revokePrivilegesFromRole: rolename, privileges: privileges };
|
|
446
|
+
if (writeConcern) {
|
|
447
|
+
cmd.writeConcern = writeConcern;
|
|
448
|
+
}
|
|
449
|
+
return await this._runCommand(cmd);
|
|
450
|
+
}
|
|
451
|
+
async getRole(rolename, options = {}) {
|
|
452
|
+
(0, helpers_1.assertArgsDefinedType)([rolename], ['string'], 'Database.getRole');
|
|
453
|
+
this._emitDatabaseApiCall('getRole', { rolename: rolename });
|
|
454
|
+
const command = (0, helpers_1.adaptOptions)({}, { rolesInfo: { role: rolename, db: this._name } }, options);
|
|
455
|
+
const result = await this._runCommand(command);
|
|
456
|
+
if (result.roles === undefined) {
|
|
457
|
+
throw new errors_1.MongoshInternalError('No roles returned from rolesInfo command');
|
|
458
|
+
}
|
|
459
|
+
for (let i = 0; i < result.roles.length; i++) {
|
|
460
|
+
if (result.roles[i].role === rolename) {
|
|
461
|
+
return result.roles[i];
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
async getRoles(options = {}) {
|
|
467
|
+
this._emitDatabaseApiCall('getRoles', { options: options });
|
|
468
|
+
const command = (0, helpers_1.adaptOptions)({}, { rolesInfo: 1 }, options);
|
|
469
|
+
return await this._runCommand(command);
|
|
470
|
+
}
|
|
471
|
+
async currentOp(opts = {}) {
|
|
472
|
+
this._emitDatabaseApiCall('currentOp', { opts: opts });
|
|
473
|
+
if (typeof opts === 'boolean') {
|
|
474
|
+
opts = { $all: opts };
|
|
475
|
+
}
|
|
476
|
+
return await this._runAdminCommand({
|
|
477
|
+
currentOp: 1,
|
|
478
|
+
...opts
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
async killOp(opId) {
|
|
482
|
+
(0, helpers_1.assertArgsDefinedType)([opId], ['number'], 'Database.killOp');
|
|
483
|
+
this._emitDatabaseApiCall('killOp', { opId });
|
|
484
|
+
return await this._runAdminCommand({
|
|
485
|
+
killOp: 1,
|
|
486
|
+
op: opId
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
async shutdownServer(opts = {}) {
|
|
490
|
+
this._emitDatabaseApiCall('shutdownServer', { opts: opts });
|
|
491
|
+
return await this._runAdminCommand({
|
|
492
|
+
shutdown: 1,
|
|
493
|
+
...opts
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
async fsyncLock() {
|
|
497
|
+
this._emitDatabaseApiCall('fsyncLock', {});
|
|
498
|
+
return await this._runAdminCommand({
|
|
499
|
+
fsync: 1,
|
|
500
|
+
lock: true
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
async fsyncUnlock() {
|
|
504
|
+
this._emitDatabaseApiCall('fsyncUnlock', {});
|
|
505
|
+
return await this._runAdminCommand({
|
|
506
|
+
fsyncUnlock: 1
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
async version() {
|
|
510
|
+
this._emitDatabaseApiCall('version', {});
|
|
511
|
+
const info = await this._runAdminCommand({
|
|
512
|
+
buildInfo: 1,
|
|
513
|
+
});
|
|
514
|
+
if (!info || info.version === undefined) {
|
|
515
|
+
throw new errors_1.MongoshRuntimeError(`Error running command serverBuildInfo ${info ? info.errmsg || '' : ''}`, errors_1.CommonErrors.CommandFailed);
|
|
516
|
+
}
|
|
517
|
+
return info.version;
|
|
518
|
+
}
|
|
519
|
+
async serverBits() {
|
|
520
|
+
this._emitDatabaseApiCall('serverBits', {});
|
|
521
|
+
const info = await this._runAdminCommand({
|
|
522
|
+
buildInfo: 1,
|
|
523
|
+
});
|
|
524
|
+
if (!info || info.bits === undefined) {
|
|
525
|
+
throw new errors_1.MongoshRuntimeError(`Error running command serverBuildInfo ${info ? info.errmsg || '' : ''}`, errors_1.CommonErrors.CommandFailed);
|
|
526
|
+
}
|
|
527
|
+
return info.bits;
|
|
528
|
+
}
|
|
529
|
+
async isMaster() {
|
|
530
|
+
this._emitDatabaseApiCall('isMaster', {});
|
|
531
|
+
const result = await this._runCommand({
|
|
532
|
+
isMaster: 1,
|
|
533
|
+
});
|
|
534
|
+
result.isWritablePrimary = result.ismaster;
|
|
535
|
+
return result;
|
|
536
|
+
}
|
|
537
|
+
async hello() {
|
|
538
|
+
this._emitDatabaseApiCall('hello', {});
|
|
539
|
+
try {
|
|
540
|
+
this._cachedHello = await this._runCommand({
|
|
541
|
+
hello: 1,
|
|
542
|
+
});
|
|
543
|
+
return this._cachedHello;
|
|
544
|
+
}
|
|
545
|
+
catch (err) {
|
|
546
|
+
if ((err === null || err === void 0 ? void 0 : err.codeName) === 'CommandNotFound') {
|
|
547
|
+
const result = await this.isMaster();
|
|
548
|
+
delete result.ismaster;
|
|
549
|
+
this._cachedHello = result;
|
|
550
|
+
return this._cachedHello;
|
|
551
|
+
}
|
|
552
|
+
throw err;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
async serverBuildInfo() {
|
|
556
|
+
this._emitDatabaseApiCall('serverBuildInfo', {});
|
|
557
|
+
return await this._runAdminCommand({
|
|
558
|
+
buildInfo: 1,
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
async serverStatus(opts = {}) {
|
|
562
|
+
this._emitDatabaseApiCall('serverStatus', { options: opts });
|
|
563
|
+
return await this._runAdminCommand({
|
|
564
|
+
serverStatus: 1, ...opts
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
async stats(scaleOrOptions = 1) {
|
|
568
|
+
(0, helpers_1.assertArgsDefinedType)([scaleOrOptions], [['number', 'object']], 'Database.stats');
|
|
569
|
+
if (typeof scaleOrOptions === 'number') {
|
|
570
|
+
scaleOrOptions = { scale: scaleOrOptions };
|
|
571
|
+
}
|
|
572
|
+
this._emitDatabaseApiCall('stats', { scale: scaleOrOptions.scale });
|
|
573
|
+
return await this._runCommand({
|
|
574
|
+
dbStats: 1,
|
|
575
|
+
scale: 1,
|
|
576
|
+
...scaleOrOptions
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
async hostInfo() {
|
|
580
|
+
this._emitDatabaseApiCall('hostInfo', {});
|
|
581
|
+
return await this._runAdminCommand({
|
|
582
|
+
hostInfo: 1,
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
async serverCmdLineOpts() {
|
|
586
|
+
this._emitDatabaseApiCall('serverCmdLineOpts', {});
|
|
587
|
+
return await this._runAdminCommand({
|
|
588
|
+
getCmdLineOpts: 1,
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
async rotateCertificates(message) {
|
|
592
|
+
this._emitDatabaseApiCall('rotateCertificates', { message });
|
|
593
|
+
return await this._runAdminCommand({
|
|
594
|
+
rotateCertificates: 1, message
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
async printCollectionStats(scale = 1) {
|
|
598
|
+
if (typeof scale !== 'number' || scale < 1) {
|
|
599
|
+
throw new errors_1.MongoshInvalidInputError(`scale has to be a number >=1, got ${scale}`, errors_1.CommonErrors.InvalidArgument);
|
|
600
|
+
}
|
|
601
|
+
this._emitDatabaseApiCall('printCollectionStats', { scale: scale });
|
|
602
|
+
const colls = await this.getCollectionNames();
|
|
603
|
+
const result = {};
|
|
604
|
+
for (const c of colls) {
|
|
605
|
+
try {
|
|
606
|
+
result[c] = await this.getCollection(c).stats({ scale });
|
|
607
|
+
}
|
|
608
|
+
catch (error) {
|
|
609
|
+
result[c] = { ok: 0, errmsg: error === null || error === void 0 ? void 0 : error.message };
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
return new index_1.CommandResult('StatsResult', result);
|
|
613
|
+
}
|
|
614
|
+
async getFreeMonitoringStatus() {
|
|
615
|
+
this._emitDatabaseApiCall('getFreeMonitoringStatus', {});
|
|
616
|
+
return await this._runAdminCommand({
|
|
617
|
+
getFreeMonitoringStatus: 1,
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
async disableFreeMonitoring() {
|
|
621
|
+
this._emitDatabaseApiCall('disableFreeMonitoring', {});
|
|
622
|
+
return await this._runAdminCommand({
|
|
623
|
+
setFreeMonitoring: 1,
|
|
624
|
+
action: 'disable'
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
async enableFreeMonitoring() {
|
|
628
|
+
this._emitDatabaseApiCall('enableFreeMonitoring', {});
|
|
629
|
+
const helloResult = await this.hello();
|
|
630
|
+
if (!helloResult.isWritablePrimary) {
|
|
631
|
+
throw new errors_1.MongoshInvalidInputError('db.enableFreeMonitoring() may only be run on a primary', errors_1.CommonErrors.InvalidOperation);
|
|
632
|
+
}
|
|
633
|
+
await this._runAdminCommand({
|
|
634
|
+
setFreeMonitoring: 1,
|
|
635
|
+
action: 'enable'
|
|
636
|
+
});
|
|
637
|
+
let result;
|
|
638
|
+
let error;
|
|
639
|
+
try {
|
|
640
|
+
result = await this._runAdminCommand({ getFreeMonitoringStatus: 1 });
|
|
641
|
+
}
|
|
642
|
+
catch (err) {
|
|
643
|
+
error = err;
|
|
644
|
+
}
|
|
645
|
+
if (error && error.codeName === 'Unauthorized' || (result && !result.ok && result.codeName === 'Unauthorized')) {
|
|
646
|
+
return 'Unable to determine status as you lack the \'checkFreeMonitoringStatus\' privilege.';
|
|
647
|
+
}
|
|
648
|
+
else if (error || !result || !result.ok) {
|
|
649
|
+
throw new errors_1.MongoshRuntimeError(`Error running command setFreeMonitoring ${result ? result.errmsg : error.errmsg}`, errors_1.CommonErrors.CommandFailed);
|
|
650
|
+
}
|
|
651
|
+
if (result.state !== 'enabled') {
|
|
652
|
+
const urlResult = await this._runAdminCommand({
|
|
653
|
+
getParameter: 1,
|
|
654
|
+
cloudFreeMonitoringEndpointURL: 1
|
|
655
|
+
});
|
|
656
|
+
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>'}'`;
|
|
657
|
+
}
|
|
658
|
+
return result;
|
|
659
|
+
}
|
|
660
|
+
async getProfilingStatus() {
|
|
661
|
+
this._emitDatabaseApiCall('getProfilingStatus', {});
|
|
662
|
+
return await this._runCommand({
|
|
663
|
+
profile: -1,
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
async setProfilingLevel(level, opts = {}) {
|
|
667
|
+
(0, helpers_1.assertArgsDefinedType)([level], ['number'], 'Database.setProfilingLevel');
|
|
668
|
+
if (level < 0 || level > 2) {
|
|
669
|
+
throw new errors_1.MongoshInvalidInputError(`Input level ${level} is out of range [0..2]`, errors_1.CommonErrors.InvalidArgument);
|
|
670
|
+
}
|
|
671
|
+
if (typeof opts === 'number') {
|
|
672
|
+
opts = { slowms: opts };
|
|
673
|
+
}
|
|
674
|
+
this._emitDatabaseApiCall('setProfilingLevel', { opts: opts });
|
|
675
|
+
return await this._runCommand({
|
|
676
|
+
profile: level,
|
|
677
|
+
...opts
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
async setLogLevel(logLevel, component) {
|
|
681
|
+
(0, helpers_1.assertArgsDefinedType)([logLevel], ['number'], 'Database.setLogLevel');
|
|
682
|
+
this._emitDatabaseApiCall('setLogLevel', { logLevel: logLevel, component: component });
|
|
683
|
+
let componentNames = [];
|
|
684
|
+
if (typeof component === 'string') {
|
|
685
|
+
componentNames = component.split('.');
|
|
686
|
+
}
|
|
687
|
+
else if (component !== undefined) {
|
|
688
|
+
throw new errors_1.MongoshInvalidInputError(`setLogLevel component must be a string: got ${typeof component}`, errors_1.CommonErrors.InvalidArgument);
|
|
689
|
+
}
|
|
690
|
+
let vDoc = { verbosity: logLevel };
|
|
691
|
+
while (componentNames.length > 0) {
|
|
692
|
+
const key = componentNames.pop();
|
|
693
|
+
vDoc = { [key]: vDoc };
|
|
694
|
+
}
|
|
695
|
+
const cmdObj = { setParameter: 1, logComponentVerbosity: vDoc };
|
|
696
|
+
return await this._runAdminCommand(cmdObj);
|
|
697
|
+
}
|
|
698
|
+
async getLogComponents() {
|
|
699
|
+
this._emitDatabaseApiCall('getLogComponents', {});
|
|
700
|
+
const cmdObj = { getParameter: 1, logComponentVerbosity: 1 };
|
|
701
|
+
const result = await this._runAdminCommand(cmdObj);
|
|
702
|
+
if (!result || result.logComponentVerbosity === undefined) {
|
|
703
|
+
throw new errors_1.MongoshRuntimeError(`Error running command ${result ? result.errmsg || '' : ''}`, errors_1.CommonErrors.CommandFailed);
|
|
704
|
+
}
|
|
705
|
+
return result.logComponentVerbosity;
|
|
706
|
+
}
|
|
707
|
+
cloneDatabase() {
|
|
708
|
+
throw new errors_1.MongoshDeprecatedError('`cloneDatabase()` was removed because it was deprecated in MongoDB 4.0');
|
|
709
|
+
}
|
|
710
|
+
cloneCollection() {
|
|
711
|
+
throw new errors_1.MongoshDeprecatedError('`cloneCollection()` was removed because it was deprecated in MongoDB 4.0');
|
|
712
|
+
}
|
|
713
|
+
copyDatabase() {
|
|
714
|
+
throw new errors_1.MongoshDeprecatedError('`copyDatabase()` was removed because it was deprecated in MongoDB 4.0');
|
|
715
|
+
}
|
|
716
|
+
async commandHelp(name) {
|
|
717
|
+
(0, helpers_1.assertArgsDefinedType)([name], ['string'], 'Database.commandHelp');
|
|
718
|
+
this._emitDatabaseApiCall('commandHelp', { name: name });
|
|
719
|
+
const command = {};
|
|
720
|
+
command[name] = 1;
|
|
721
|
+
command.help = true;
|
|
722
|
+
const result = await this._runCommand(command);
|
|
723
|
+
if (!result || result.help === undefined) {
|
|
724
|
+
throw new errors_1.MongoshRuntimeError(`Error running command commandHelp ${result ? result.errmsg || '' : ''}`, errors_1.CommonErrors.CommandFailed);
|
|
725
|
+
}
|
|
726
|
+
return result.help;
|
|
727
|
+
}
|
|
728
|
+
async listCommands() {
|
|
729
|
+
this._emitDatabaseApiCall('listCommands', {});
|
|
730
|
+
const result = await this._runCommand({
|
|
731
|
+
listCommands: 1,
|
|
732
|
+
});
|
|
733
|
+
if (!result || result.commands === undefined) {
|
|
734
|
+
throw new errors_1.MongoshRuntimeError(`Error running command listCommands ${result ? result.errmsg || '' : ''}`, errors_1.CommonErrors.CommandFailed);
|
|
735
|
+
}
|
|
736
|
+
for (const cmdDescription of Object.values(result.commands)) {
|
|
737
|
+
if ('slaveOk' in cmdDescription) {
|
|
738
|
+
cmdDescription.secondaryOk = cmdDescription.slaveOk;
|
|
739
|
+
delete cmdDescription.slaveOk;
|
|
740
|
+
}
|
|
741
|
+
if ('slaveOverrideOk' in cmdDescription) {
|
|
742
|
+
cmdDescription.secondaryOverrideOk = cmdDescription.slaveOverrideOk;
|
|
743
|
+
delete cmdDescription.slaveOverrideOk;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
return new index_1.CommandResult('ListCommandsResult', result.commands);
|
|
747
|
+
}
|
|
748
|
+
async getLastErrorObj(w, wTimeout, j) {
|
|
749
|
+
await this._instanceState.printDeprecationWarning('Database.getLastErrorObj() is deprecated and will be removed in the future.');
|
|
750
|
+
this._emitDatabaseApiCall('getLastErrorObj', { w: w, wTimeout: wTimeout, j: j });
|
|
751
|
+
return await this._getLastErrorObj(w, wTimeout, j);
|
|
752
|
+
}
|
|
753
|
+
async getLastError(w, wTimeout) {
|
|
754
|
+
await this._instanceState.printDeprecationWarning('Database.getLastError() is deprecated and will be removed in the future.');
|
|
755
|
+
this._emitDatabaseApiCall('getLastError', { w: w, wTimeout: wTimeout });
|
|
756
|
+
const result = await this._getLastErrorObj(w, wTimeout);
|
|
757
|
+
return result.err || null;
|
|
758
|
+
}
|
|
759
|
+
async printShardingStatus(verbose = false) {
|
|
760
|
+
this._emitDatabaseApiCall('printShardingStatus', { verbose });
|
|
761
|
+
const result = await (0, helpers_1.getPrintableShardStatus)(await (0, helpers_1.getConfigDB)(this), verbose);
|
|
762
|
+
return new index_1.CommandResult('StatsResult', result);
|
|
763
|
+
}
|
|
764
|
+
async printSecondaryReplicationInfo() {
|
|
765
|
+
let startOptimeDate = null;
|
|
766
|
+
const local = this.getSiblingDB('local');
|
|
767
|
+
if (await local.getCollection('system.replset').countDocuments({}) !== 0) {
|
|
768
|
+
const status = await this._runAdminCommand({ 'replSetGetStatus': 1 });
|
|
769
|
+
let primary = null;
|
|
770
|
+
for (const member of status.members) {
|
|
771
|
+
if (member.state === 1) {
|
|
772
|
+
primary = member;
|
|
773
|
+
break;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
if (primary) {
|
|
777
|
+
startOptimeDate = primary.optimeDate;
|
|
778
|
+
}
|
|
779
|
+
else {
|
|
780
|
+
startOptimeDate = new Date(0, 0);
|
|
781
|
+
for (const member of status.members) {
|
|
782
|
+
if (member.optimeDate > startOptimeDate) {
|
|
783
|
+
startOptimeDate = member.optimeDate;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
const result = {};
|
|
788
|
+
for (const node of status.members) {
|
|
789
|
+
const nodeResult = {};
|
|
790
|
+
if (node === null || node === undefined) {
|
|
791
|
+
throw new errors_1.MongoshRuntimeError('Member returned from command replSetGetStatus is null', errors_1.CommonErrors.CommandFailed);
|
|
792
|
+
}
|
|
793
|
+
if (node.state === 1 || node.state === 7) {
|
|
794
|
+
continue;
|
|
795
|
+
}
|
|
796
|
+
if (node.optime && node.health !== 0) {
|
|
797
|
+
if (startOptimeDate === null || startOptimeDate === undefined) {
|
|
798
|
+
throw new errors_1.MongoshRuntimeError('getReplLag startOptimeDate is null', errors_1.CommonErrors.CommandFailed);
|
|
799
|
+
}
|
|
800
|
+
if (startOptimeDate) {
|
|
801
|
+
nodeResult.syncedTo = node.optimeDate.toString();
|
|
802
|
+
}
|
|
803
|
+
const ago = (node.optimeDate - startOptimeDate) / 1000;
|
|
804
|
+
const hrs = Math.round(ago / 36) / 100;
|
|
805
|
+
let suffix = '';
|
|
806
|
+
if (primary) {
|
|
807
|
+
suffix = 'primary ';
|
|
808
|
+
}
|
|
809
|
+
else {
|
|
810
|
+
suffix = 'freshest member (no primary available at the moment)';
|
|
811
|
+
}
|
|
812
|
+
nodeResult.replLag = `${Math.round(ago)} secs (${hrs} hrs) behind the ${suffix}`;
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
nodeResult['no replication info, yet. State'] = node.stateStr;
|
|
816
|
+
}
|
|
817
|
+
result[`source: ${node.name}`] = nodeResult;
|
|
818
|
+
}
|
|
819
|
+
return new index_1.CommandResult('StatsResult', result);
|
|
820
|
+
}
|
|
821
|
+
throw new errors_1.MongoshInvalidInputError('local.system.replset is empty. Are you connected to a replica set?', error_codes_1.ShellApiErrors.NotConnectedToReplicaSet);
|
|
822
|
+
}
|
|
823
|
+
async getReplicationInfo() {
|
|
824
|
+
const localdb = this.getSiblingDB('local');
|
|
825
|
+
const result = {};
|
|
826
|
+
const oplog = 'oplog.rs';
|
|
827
|
+
const localCollections = await localdb.getCollectionNames();
|
|
828
|
+
if (!localCollections.includes(oplog)) {
|
|
829
|
+
throw new errors_1.MongoshInvalidInputError('Replication not detected. Are you connected to a replset?', error_codes_1.ShellApiErrors.NotConnectedToReplicaSet);
|
|
830
|
+
}
|
|
831
|
+
const ol = localdb.getCollection(oplog);
|
|
832
|
+
const [olStats, first, last] = await Promise.all([
|
|
833
|
+
ol.stats(),
|
|
834
|
+
(async () => (await ol.find()).sort({ $natural: 1 }).limit(1).tryNext())(),
|
|
835
|
+
(async () => (await ol.find()).sort({ $natural: -1 }).limit(1).tryNext())()
|
|
836
|
+
]);
|
|
837
|
+
if (!(olStats === null || olStats === void 0 ? void 0 : olStats.maxSize)) {
|
|
838
|
+
throw new errors_1.MongoshRuntimeError(`Could not get stats for local.${oplog} collection. collstats returned ${JSON.stringify(olStats)}`, errors_1.CommonErrors.CommandFailed);
|
|
839
|
+
}
|
|
840
|
+
result.configuredLogSizeMB = olStats.maxSize / (1024 * 1024);
|
|
841
|
+
result.logSizeMB = Math.max(olStats.maxSize, olStats.size) / (1024 * 1024);
|
|
842
|
+
result.usedMB = olStats.size / (1024 * 1024);
|
|
843
|
+
result.usedMB = Math.ceil(result.usedMB * 100) / 100;
|
|
844
|
+
if (first === null || last === null) {
|
|
845
|
+
throw new errors_1.MongoshRuntimeError('objects not found in local.oplog.$main -- is this a new and empty db instance?', errors_1.CommonErrors.CommandFailed);
|
|
846
|
+
}
|
|
847
|
+
let tfirst = first.ts;
|
|
848
|
+
let tlast = last.ts;
|
|
849
|
+
if (tfirst && tlast) {
|
|
850
|
+
tfirst = (0, helpers_1.tsToSeconds)(tfirst);
|
|
851
|
+
tlast = (0, helpers_1.tsToSeconds)(tlast);
|
|
852
|
+
result.timeDiff = tlast - tfirst;
|
|
853
|
+
result.timeDiffHours = Math.round(result.timeDiff / 36) / 100;
|
|
854
|
+
result.tFirst = (new Date(tfirst * 1000)).toString();
|
|
855
|
+
result.tLast = (new Date(tlast * 1000)).toString();
|
|
856
|
+
result.now = Date();
|
|
857
|
+
}
|
|
858
|
+
else {
|
|
859
|
+
result.errmsg = 'ts element not found in oplog objects';
|
|
860
|
+
}
|
|
861
|
+
return result;
|
|
862
|
+
}
|
|
863
|
+
async printReplicationInfo() {
|
|
864
|
+
const result = {};
|
|
865
|
+
let replInfo;
|
|
866
|
+
try {
|
|
867
|
+
replInfo = await this.getReplicationInfo();
|
|
868
|
+
}
|
|
869
|
+
catch (error) {
|
|
870
|
+
const helloResult = await this.hello();
|
|
871
|
+
if (helloResult.arbiterOnly) {
|
|
872
|
+
return new index_1.CommandResult('StatsResult', { message: 'cannot provide replication status from an arbiter' });
|
|
873
|
+
}
|
|
874
|
+
else if (!helloResult.isWritablePrimary) {
|
|
875
|
+
const secondaryInfo = await this.printSecondaryReplicationInfo();
|
|
876
|
+
return new index_1.CommandResult('StatsResult', {
|
|
877
|
+
message: 'this is a secondary, printing secondary replication info.',
|
|
878
|
+
...secondaryInfo.value
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
throw error;
|
|
882
|
+
}
|
|
883
|
+
result['actual oplog size'] = `${replInfo.logSizeMB} MB`;
|
|
884
|
+
result['configured oplog size'] = `${replInfo.configuredLogSizeMB} MB`;
|
|
885
|
+
result['log length start to end'] = `${replInfo.timeDiff} secs (${replInfo.timeDiffHours} hrs)`;
|
|
886
|
+
result['oplog first event time'] = replInfo.tFirst;
|
|
887
|
+
result['oplog last event time'] = replInfo.tLast;
|
|
888
|
+
result.now = replInfo.now;
|
|
889
|
+
return new index_1.CommandResult('StatsResult', result);
|
|
890
|
+
}
|
|
891
|
+
printSlaveReplicationInfo() {
|
|
892
|
+
throw new errors_1.MongoshDeprecatedError('Method deprecated, use db.printSecondaryReplicationInfo instead');
|
|
893
|
+
}
|
|
894
|
+
async setSecondaryOk() {
|
|
895
|
+
await this._mongo.setSecondaryOk();
|
|
896
|
+
}
|
|
897
|
+
async watch(pipeline = [], options = {}) {
|
|
898
|
+
if (!Array.isArray(pipeline)) {
|
|
899
|
+
options = pipeline;
|
|
900
|
+
pipeline = [];
|
|
901
|
+
}
|
|
902
|
+
this._emitDatabaseApiCall('watch', { pipeline, options });
|
|
903
|
+
const cursor = new change_stream_cursor_1.default(this._mongo._serviceProvider.watch(pipeline, {
|
|
904
|
+
...await this._baseOptions(),
|
|
905
|
+
...options
|
|
906
|
+
}, {}, this._name), this._name, this._mongo);
|
|
907
|
+
if (!options.resumeAfter && !options.startAfter && !options.startAtOperationTime) {
|
|
908
|
+
await cursor.tryNext();
|
|
909
|
+
}
|
|
910
|
+
this._mongo._instanceState.currentCursor = cursor;
|
|
911
|
+
return cursor;
|
|
912
|
+
}
|
|
913
|
+
async sql(sqlString, options) {
|
|
914
|
+
var _a;
|
|
915
|
+
this._emitDatabaseApiCall('sql', { sqlString: sqlString, options });
|
|
916
|
+
await this._instanceState.shellApi.print('Note: this is an experimental feature that may be subject to change in future releases.');
|
|
917
|
+
const cursor = await this.aggregate([{
|
|
918
|
+
$sql: {
|
|
919
|
+
statement: sqlString,
|
|
920
|
+
format: 'jdbc',
|
|
921
|
+
dialect: 'mongosql',
|
|
922
|
+
formatVersion: 1
|
|
923
|
+
}
|
|
924
|
+
}], options);
|
|
925
|
+
try {
|
|
926
|
+
await cursor.hasNext();
|
|
927
|
+
}
|
|
928
|
+
catch (err) {
|
|
929
|
+
if (((_a = err.code) === null || _a === void 0 ? void 0 : _a.valueOf()) === 40324) {
|
|
930
|
+
throw new errors_1.MongoshRuntimeError('db.sql currently only works when connected to a Data Lake', errors_1.CommonErrors.CommandFailed);
|
|
931
|
+
}
|
|
932
|
+
throw err;
|
|
933
|
+
}
|
|
934
|
+
return cursor;
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
__decorate([
|
|
938
|
+
(0, decorators_1.returnType)('Mongo')
|
|
939
|
+
], Database.prototype, "getMongo", null);
|
|
940
|
+
__decorate([
|
|
941
|
+
decorators_1.returnsPromise,
|
|
942
|
+
(0, decorators_1.apiVersions)([1])
|
|
943
|
+
], Database.prototype, "getCollectionNames", null);
|
|
944
|
+
__decorate([
|
|
945
|
+
decorators_1.returnsPromise,
|
|
946
|
+
(0, decorators_1.serverVersions)(['3.0.0', enums_1.ServerVersions.latest]),
|
|
947
|
+
(0, decorators_1.apiVersions)([1])
|
|
948
|
+
], Database.prototype, "getCollectionInfos", null);
|
|
949
|
+
__decorate([
|
|
950
|
+
decorators_1.returnsPromise,
|
|
951
|
+
(0, decorators_1.apiVersions)([1])
|
|
952
|
+
], Database.prototype, "runCommand", null);
|
|
953
|
+
__decorate([
|
|
954
|
+
decorators_1.returnsPromise,
|
|
955
|
+
(0, decorators_1.serverVersions)(['3.4.0', enums_1.ServerVersions.latest]),
|
|
956
|
+
(0, decorators_1.apiVersions)([1])
|
|
957
|
+
], Database.prototype, "adminCommand", null);
|
|
958
|
+
__decorate([
|
|
959
|
+
decorators_1.returnsPromise,
|
|
960
|
+
(0, decorators_1.returnType)('AggregationCursor'),
|
|
961
|
+
(0, decorators_1.apiVersions)([1])
|
|
962
|
+
], Database.prototype, "aggregate", null);
|
|
963
|
+
__decorate([
|
|
964
|
+
(0, decorators_1.returnType)('Database')
|
|
965
|
+
], Database.prototype, "getSiblingDB", null);
|
|
966
|
+
__decorate([
|
|
967
|
+
(0, decorators_1.returnType)('Collection')
|
|
968
|
+
], Database.prototype, "getCollection", null);
|
|
969
|
+
__decorate([
|
|
970
|
+
decorators_1.returnsPromise,
|
|
971
|
+
(0, decorators_1.apiVersions)([1])
|
|
972
|
+
], Database.prototype, "dropDatabase", null);
|
|
973
|
+
__decorate([
|
|
974
|
+
decorators_1.returnsPromise,
|
|
975
|
+
(0, decorators_1.apiVersions)([])
|
|
976
|
+
], Database.prototype, "createUser", null);
|
|
977
|
+
__decorate([
|
|
978
|
+
decorators_1.returnsPromise
|
|
979
|
+
], Database.prototype, "updateUser", null);
|
|
980
|
+
__decorate([
|
|
981
|
+
decorators_1.returnsPromise,
|
|
982
|
+
(0, decorators_1.apiVersions)([])
|
|
983
|
+
], Database.prototype, "changeUserPassword", null);
|
|
984
|
+
__decorate([
|
|
985
|
+
decorators_1.returnsPromise,
|
|
986
|
+
(0, decorators_1.apiVersions)([])
|
|
987
|
+
], Database.prototype, "logout", null);
|
|
988
|
+
__decorate([
|
|
989
|
+
decorators_1.returnsPromise,
|
|
990
|
+
(0, decorators_1.apiVersions)([])
|
|
991
|
+
], Database.prototype, "dropUser", null);
|
|
992
|
+
__decorate([
|
|
993
|
+
decorators_1.returnsPromise,
|
|
994
|
+
(0, decorators_1.apiVersions)([])
|
|
995
|
+
], Database.prototype, "dropAllUsers", null);
|
|
996
|
+
__decorate([
|
|
997
|
+
decorators_1.returnsPromise
|
|
998
|
+
], Database.prototype, "auth", null);
|
|
999
|
+
__decorate([
|
|
1000
|
+
decorators_1.returnsPromise,
|
|
1001
|
+
(0, decorators_1.apiVersions)([])
|
|
1002
|
+
], Database.prototype, "grantRolesToUser", null);
|
|
1003
|
+
__decorate([
|
|
1004
|
+
decorators_1.returnsPromise,
|
|
1005
|
+
(0, decorators_1.apiVersions)([])
|
|
1006
|
+
], Database.prototype, "revokeRolesFromUser", null);
|
|
1007
|
+
__decorate([
|
|
1008
|
+
decorators_1.returnsPromise,
|
|
1009
|
+
(0, decorators_1.apiVersions)([])
|
|
1010
|
+
], Database.prototype, "getUser", null);
|
|
1011
|
+
__decorate([
|
|
1012
|
+
decorators_1.returnsPromise,
|
|
1013
|
+
(0, decorators_1.apiVersions)([])
|
|
1014
|
+
], Database.prototype, "getUsers", null);
|
|
1015
|
+
__decorate([
|
|
1016
|
+
decorators_1.returnsPromise,
|
|
1017
|
+
(0, decorators_1.apiVersions)([1])
|
|
1018
|
+
], Database.prototype, "createCollection", null);
|
|
1019
|
+
__decorate([
|
|
1020
|
+
decorators_1.returnsPromise,
|
|
1021
|
+
(0, decorators_1.apiVersions)([1])
|
|
1022
|
+
], Database.prototype, "createView", null);
|
|
1023
|
+
__decorate([
|
|
1024
|
+
decorators_1.returnsPromise,
|
|
1025
|
+
(0, decorators_1.apiVersions)([])
|
|
1026
|
+
], Database.prototype, "createRole", null);
|
|
1027
|
+
__decorate([
|
|
1028
|
+
decorators_1.returnsPromise,
|
|
1029
|
+
(0, decorators_1.apiVersions)([])
|
|
1030
|
+
], Database.prototype, "updateRole", null);
|
|
1031
|
+
__decorate([
|
|
1032
|
+
decorators_1.returnsPromise,
|
|
1033
|
+
(0, decorators_1.apiVersions)([])
|
|
1034
|
+
], Database.prototype, "dropRole", null);
|
|
1035
|
+
__decorate([
|
|
1036
|
+
decorators_1.returnsPromise
|
|
1037
|
+
], Database.prototype, "dropAllRoles", null);
|
|
1038
|
+
__decorate([
|
|
1039
|
+
decorators_1.returnsPromise,
|
|
1040
|
+
(0, decorators_1.apiVersions)([])
|
|
1041
|
+
], Database.prototype, "grantRolesToRole", null);
|
|
1042
|
+
__decorate([
|
|
1043
|
+
decorators_1.returnsPromise,
|
|
1044
|
+
(0, decorators_1.apiVersions)([])
|
|
1045
|
+
], Database.prototype, "revokeRolesFromRole", null);
|
|
1046
|
+
__decorate([
|
|
1047
|
+
decorators_1.returnsPromise
|
|
1048
|
+
], Database.prototype, "grantPrivilegesToRole", null);
|
|
1049
|
+
__decorate([
|
|
1050
|
+
decorators_1.returnsPromise,
|
|
1051
|
+
(0, decorators_1.apiVersions)([])
|
|
1052
|
+
], Database.prototype, "revokePrivilegesFromRole", null);
|
|
1053
|
+
__decorate([
|
|
1054
|
+
decorators_1.returnsPromise,
|
|
1055
|
+
(0, decorators_1.apiVersions)([])
|
|
1056
|
+
], Database.prototype, "getRole", null);
|
|
1057
|
+
__decorate([
|
|
1058
|
+
decorators_1.returnsPromise,
|
|
1059
|
+
(0, decorators_1.apiVersions)([])
|
|
1060
|
+
], Database.prototype, "getRoles", null);
|
|
1061
|
+
__decorate([
|
|
1062
|
+
decorators_1.returnsPromise,
|
|
1063
|
+
(0, decorators_1.apiVersions)([])
|
|
1064
|
+
], Database.prototype, "currentOp", null);
|
|
1065
|
+
__decorate([
|
|
1066
|
+
decorators_1.returnsPromise,
|
|
1067
|
+
(0, decorators_1.apiVersions)([])
|
|
1068
|
+
], Database.prototype, "killOp", null);
|
|
1069
|
+
__decorate([
|
|
1070
|
+
decorators_1.returnsPromise,
|
|
1071
|
+
(0, decorators_1.apiVersions)([])
|
|
1072
|
+
], Database.prototype, "shutdownServer", null);
|
|
1073
|
+
__decorate([
|
|
1074
|
+
decorators_1.returnsPromise,
|
|
1075
|
+
(0, decorators_1.apiVersions)([])
|
|
1076
|
+
], Database.prototype, "fsyncLock", null);
|
|
1077
|
+
__decorate([
|
|
1078
|
+
decorators_1.returnsPromise,
|
|
1079
|
+
(0, decorators_1.apiVersions)([])
|
|
1080
|
+
], Database.prototype, "fsyncUnlock", null);
|
|
1081
|
+
__decorate([
|
|
1082
|
+
decorators_1.returnsPromise,
|
|
1083
|
+
(0, decorators_1.apiVersions)([])
|
|
1084
|
+
], Database.prototype, "version", null);
|
|
1085
|
+
__decorate([
|
|
1086
|
+
decorators_1.returnsPromise,
|
|
1087
|
+
(0, decorators_1.apiVersions)([])
|
|
1088
|
+
], Database.prototype, "serverBits", null);
|
|
1089
|
+
__decorate([
|
|
1090
|
+
decorators_1.returnsPromise,
|
|
1091
|
+
(0, decorators_1.apiVersions)([])
|
|
1092
|
+
], Database.prototype, "isMaster", null);
|
|
1093
|
+
__decorate([
|
|
1094
|
+
decorators_1.returnsPromise,
|
|
1095
|
+
(0, decorators_1.apiVersions)([1]),
|
|
1096
|
+
(0, decorators_1.serverVersions)(['5.0.0', enums_1.ServerVersions.latest])
|
|
1097
|
+
], Database.prototype, "hello", null);
|
|
1098
|
+
__decorate([
|
|
1099
|
+
decorators_1.returnsPromise,
|
|
1100
|
+
(0, decorators_1.apiVersions)([])
|
|
1101
|
+
], Database.prototype, "serverBuildInfo", null);
|
|
1102
|
+
__decorate([
|
|
1103
|
+
decorators_1.returnsPromise,
|
|
1104
|
+
(0, decorators_1.apiVersions)([])
|
|
1105
|
+
], Database.prototype, "serverStatus", null);
|
|
1106
|
+
__decorate([
|
|
1107
|
+
decorators_1.returnsPromise,
|
|
1108
|
+
(0, decorators_1.apiVersions)([])
|
|
1109
|
+
], Database.prototype, "stats", null);
|
|
1110
|
+
__decorate([
|
|
1111
|
+
decorators_1.returnsPromise,
|
|
1112
|
+
(0, decorators_1.apiVersions)([])
|
|
1113
|
+
], Database.prototype, "hostInfo", null);
|
|
1114
|
+
__decorate([
|
|
1115
|
+
decorators_1.returnsPromise,
|
|
1116
|
+
(0, decorators_1.apiVersions)([])
|
|
1117
|
+
], Database.prototype, "serverCmdLineOpts", null);
|
|
1118
|
+
__decorate([
|
|
1119
|
+
decorators_1.returnsPromise,
|
|
1120
|
+
(0, decorators_1.serverVersions)(['5.0.0', enums_1.ServerVersions.latest]),
|
|
1121
|
+
(0, decorators_1.apiVersions)([])
|
|
1122
|
+
], Database.prototype, "rotateCertificates", null);
|
|
1123
|
+
__decorate([
|
|
1124
|
+
decorators_1.returnsPromise,
|
|
1125
|
+
(0, decorators_1.apiVersions)([])
|
|
1126
|
+
], Database.prototype, "printCollectionStats", null);
|
|
1127
|
+
__decorate([
|
|
1128
|
+
decorators_1.returnsPromise,
|
|
1129
|
+
(0, decorators_1.apiVersions)([])
|
|
1130
|
+
], Database.prototype, "getFreeMonitoringStatus", null);
|
|
1131
|
+
__decorate([
|
|
1132
|
+
decorators_1.returnsPromise,
|
|
1133
|
+
(0, decorators_1.apiVersions)([])
|
|
1134
|
+
], Database.prototype, "disableFreeMonitoring", null);
|
|
1135
|
+
__decorate([
|
|
1136
|
+
decorators_1.returnsPromise,
|
|
1137
|
+
(0, decorators_1.apiVersions)([])
|
|
1138
|
+
], Database.prototype, "enableFreeMonitoring", null);
|
|
1139
|
+
__decorate([
|
|
1140
|
+
decorators_1.returnsPromise,
|
|
1141
|
+
(0, decorators_1.apiVersions)([])
|
|
1142
|
+
], Database.prototype, "getProfilingStatus", null);
|
|
1143
|
+
__decorate([
|
|
1144
|
+
decorators_1.returnsPromise,
|
|
1145
|
+
(0, decorators_1.apiVersions)([])
|
|
1146
|
+
], Database.prototype, "setProfilingLevel", null);
|
|
1147
|
+
__decorate([
|
|
1148
|
+
decorators_1.returnsPromise,
|
|
1149
|
+
(0, decorators_1.apiVersions)([])
|
|
1150
|
+
], Database.prototype, "setLogLevel", null);
|
|
1151
|
+
__decorate([
|
|
1152
|
+
decorators_1.returnsPromise,
|
|
1153
|
+
(0, decorators_1.apiVersions)([])
|
|
1154
|
+
], Database.prototype, "getLogComponents", null);
|
|
1155
|
+
__decorate([
|
|
1156
|
+
decorators_1.deprecated
|
|
1157
|
+
], Database.prototype, "cloneDatabase", null);
|
|
1158
|
+
__decorate([
|
|
1159
|
+
decorators_1.deprecated
|
|
1160
|
+
], Database.prototype, "cloneCollection", null);
|
|
1161
|
+
__decorate([
|
|
1162
|
+
decorators_1.deprecated
|
|
1163
|
+
], Database.prototype, "copyDatabase", null);
|
|
1164
|
+
__decorate([
|
|
1165
|
+
decorators_1.returnsPromise,
|
|
1166
|
+
(0, decorators_1.apiVersions)([1])
|
|
1167
|
+
], Database.prototype, "commandHelp", null);
|
|
1168
|
+
__decorate([
|
|
1169
|
+
decorators_1.returnsPromise,
|
|
1170
|
+
(0, decorators_1.apiVersions)([])
|
|
1171
|
+
], Database.prototype, "listCommands", null);
|
|
1172
|
+
__decorate([
|
|
1173
|
+
decorators_1.deprecated,
|
|
1174
|
+
decorators_1.returnsPromise,
|
|
1175
|
+
(0, decorators_1.apiVersions)([])
|
|
1176
|
+
], Database.prototype, "getLastErrorObj", null);
|
|
1177
|
+
__decorate([
|
|
1178
|
+
decorators_1.deprecated,
|
|
1179
|
+
decorators_1.returnsPromise,
|
|
1180
|
+
(0, decorators_1.apiVersions)([])
|
|
1181
|
+
], Database.prototype, "getLastError", null);
|
|
1182
|
+
__decorate([
|
|
1183
|
+
decorators_1.returnsPromise,
|
|
1184
|
+
(0, decorators_1.topologies)([enums_1.Topologies.Sharded]),
|
|
1185
|
+
(0, decorators_1.apiVersions)([1])
|
|
1186
|
+
], Database.prototype, "printShardingStatus", null);
|
|
1187
|
+
__decorate([
|
|
1188
|
+
decorators_1.returnsPromise,
|
|
1189
|
+
(0, decorators_1.topologies)([enums_1.Topologies.ReplSet]),
|
|
1190
|
+
(0, decorators_1.apiVersions)([])
|
|
1191
|
+
], Database.prototype, "printSecondaryReplicationInfo", null);
|
|
1192
|
+
__decorate([
|
|
1193
|
+
decorators_1.returnsPromise,
|
|
1194
|
+
(0, decorators_1.topologies)([enums_1.Topologies.ReplSet]),
|
|
1195
|
+
(0, decorators_1.apiVersions)([])
|
|
1196
|
+
], Database.prototype, "getReplicationInfo", null);
|
|
1197
|
+
__decorate([
|
|
1198
|
+
decorators_1.returnsPromise,
|
|
1199
|
+
(0, decorators_1.apiVersions)([]),
|
|
1200
|
+
(0, decorators_1.topologies)([enums_1.Topologies.ReplSet])
|
|
1201
|
+
], Database.prototype, "printReplicationInfo", null);
|
|
1202
|
+
__decorate([
|
|
1203
|
+
decorators_1.deprecated
|
|
1204
|
+
], Database.prototype, "printSlaveReplicationInfo", null);
|
|
1205
|
+
__decorate([
|
|
1206
|
+
decorators_1.deprecated,
|
|
1207
|
+
decorators_1.returnsPromise
|
|
1208
|
+
], Database.prototype, "setSecondaryOk", null);
|
|
1209
|
+
__decorate([
|
|
1210
|
+
(0, decorators_1.serverVersions)(['3.1.0', enums_1.ServerVersions.latest]),
|
|
1211
|
+
(0, decorators_1.topologies)([enums_1.Topologies.ReplSet, enums_1.Topologies.Sharded]),
|
|
1212
|
+
(0, decorators_1.apiVersions)([1]),
|
|
1213
|
+
decorators_1.returnsPromise
|
|
1214
|
+
], Database.prototype, "watch", null);
|
|
1215
|
+
__decorate([
|
|
1216
|
+
(0, decorators_1.serverVersions)(['4.4.0', enums_1.ServerVersions.latest]),
|
|
1217
|
+
decorators_1.returnsPromise,
|
|
1218
|
+
(0, decorators_1.returnType)('AggregationCursor')
|
|
1219
|
+
], Database.prototype, "sql", null);
|
|
1220
|
+
Database = __decorate([
|
|
1221
|
+
decorators_1.shellApiClassDefault
|
|
1222
|
+
], Database);
|
|
1223
|
+
exports.default = Database;
|
|
1224
1224
|
//# sourceMappingURL=database.js.map
|