@qp-mongosh/shell-api 0.0.0-dev.28 → 0.0.0-dev.29
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/lib/abstract-cursor.d.ts +33 -0
- package/lib/abstract-cursor.js +192 -0
- package/lib/abstract-cursor.js.map +1 -0
- package/lib/aggregation-cursor.d.ts +6 -0
- package/lib/aggregation-cursor.js +20 -0
- package/lib/aggregation-cursor.js.map +1 -0
- package/lib/bulk.d.ts +43 -0
- package/lib/bulk.js +224 -0
- package/lib/bulk.js.map +1 -0
- package/lib/change-stream-cursor.d.ts +28 -0
- package/lib/change-stream-cursor.js +112 -0
- package/lib/change-stream-cursor.js.map +1 -0
- package/lib/collection.d.ts +95 -0
- package/lib/collection.js +965 -0
- package/lib/collection.js.map +1 -0
- package/lib/cursor.d.ts +32 -0
- package/lib/cursor.js +216 -0
- package/lib/cursor.js.map +1 -0
- package/lib/database.d.ts +116 -0
- package/lib/database.js +1224 -0
- package/lib/database.js.map +1 -0
- package/lib/dbquery.d.ts +8 -0
- package/lib/dbquery.js +29 -0
- package/lib/dbquery.js.map +1 -0
- package/lib/decorators.d.ts +73 -0
- package/lib/decorators.js +396 -0
- package/lib/decorators.js.map +1 -0
- package/lib/enums.d.ts +28 -0
- package/lib/enums.js +34 -0
- package/lib/enums.js.map +1 -0
- package/lib/error-codes.d.ts +12 -0
- package/lib/error-codes.js +20 -0
- package/lib/error-codes.js.map +1 -0
- package/lib/explainable-cursor.d.ts +11 -0
- package/lib/explainable-cursor.js +32 -0
- package/lib/explainable-cursor.js.map +1 -0
- package/lib/explainable.d.ts +32 -0
- package/lib/explainable.js +167 -0
- package/lib/explainable.js.map +1 -0
- package/lib/field-level-encryption.d.ts +50 -0
- package/lib/field-level-encryption.js +177 -0
- package/lib/field-level-encryption.js.map +1 -0
- package/lib/help.d.ts +22 -0
- package/lib/help.js +27 -0
- package/lib/help.js.map +1 -0
- package/lib/helpers.d.ts +71 -0
- package/lib/helpers.js +589 -0
- package/lib/helpers.js.map +1 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +46 -0
- package/lib/index.js.map +1 -0
- package/lib/interruptor.d.ts +19 -0
- package/lib/interruptor.js +63 -0
- package/lib/interruptor.js.map +1 -0
- package/lib/mongo-errors.d.ts +5 -0
- package/lib/mongo-errors.js +38 -0
- package/lib/mongo-errors.js.map +1 -0
- package/lib/mongo.d.ts +75 -0
- package/lib/mongo.js +477 -0
- package/lib/mongo.js.map +1 -0
- package/lib/no-db.d.ts +5 -0
- package/lib/no-db.js +29 -0
- package/lib/no-db.js.map +1 -0
- package/lib/plan-cache.d.ts +16 -0
- package/lib/plan-cache.js +71 -0
- package/lib/plan-cache.js.map +1 -0
- package/lib/replica-set.d.ts +45 -0
- package/lib/replica-set.js +315 -0
- package/lib/replica-set.js.map +1 -0
- package/lib/result.d.ts +61 -0
- package/lib/result.js +105 -0
- package/lib/result.js.map +1 -0
- package/lib/session.d.ts +25 -0
- package/lib/session.js +89 -0
- package/lib/session.js.map +1 -0
- package/lib/shard.d.ts +42 -0
- package/lib/shard.js +415 -0
- package/lib/shard.js.map +1 -0
- package/lib/shell-api.d.ts +52 -0
- package/lib/shell-api.js +299 -0
- package/lib/shell-api.js.map +1 -0
- package/lib/shell-bson.d.ts +40 -0
- package/lib/shell-bson.js +160 -0
- package/lib/shell-bson.js.map +1 -0
- package/lib/shell-instance-state.d.ts +77 -0
- package/lib/shell-instance-state.js +390 -0
- package/lib/shell-instance-state.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,965 @@
|
|
|
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 decorators_1 = require("./decorators");
|
|
13
|
+
const enums_1 = require("./enums");
|
|
14
|
+
const helpers_1 = require("./helpers");
|
|
15
|
+
const index_1 = require("./index");
|
|
16
|
+
const errors_1 = require("@qp-mongosh/errors");
|
|
17
|
+
const bulk_1 = __importDefault(require("./bulk"));
|
|
18
|
+
const history_1 = require("@qp-mongosh/history");
|
|
19
|
+
const plan_cache_1 = __importDefault(require("./plan-cache"));
|
|
20
|
+
const change_stream_cursor_1 = __importDefault(require("./change-stream-cursor"));
|
|
21
|
+
const error_codes_1 = require("./error-codes");
|
|
22
|
+
let Collection = class Collection extends decorators_1.ShellApiWithMongoClass {
|
|
23
|
+
constructor(mongo, database, name) {
|
|
24
|
+
super();
|
|
25
|
+
this._mongo = mongo;
|
|
26
|
+
this._database = database;
|
|
27
|
+
this._name = name;
|
|
28
|
+
const proxy = new Proxy(this, {
|
|
29
|
+
get: (target, prop) => {
|
|
30
|
+
if (prop in target) {
|
|
31
|
+
return target[prop];
|
|
32
|
+
}
|
|
33
|
+
if (typeof prop !== 'string' ||
|
|
34
|
+
prop.startsWith('_') ||
|
|
35
|
+
!(0, helpers_1.isValidCollectionName)(prop)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
return database.getCollection(`${name}.${prop}`);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return proxy;
|
|
42
|
+
}
|
|
43
|
+
[enums_1.namespaceInfo]() {
|
|
44
|
+
return { db: this._database.getName(), collection: this._name };
|
|
45
|
+
}
|
|
46
|
+
[enums_1.asPrintable]() {
|
|
47
|
+
return `${this._database.getName()}.${this._name}`;
|
|
48
|
+
}
|
|
49
|
+
_emitCollectionApiCall(methodName, methodArguments = {}) {
|
|
50
|
+
this._mongo._instanceState.emitApiCallWithArgs({
|
|
51
|
+
method: methodName,
|
|
52
|
+
class: 'Collection',
|
|
53
|
+
db: this._database._name,
|
|
54
|
+
coll: this._name,
|
|
55
|
+
arguments: methodArguments
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async aggregate(...args) {
|
|
59
|
+
let options;
|
|
60
|
+
let pipeline;
|
|
61
|
+
if (args.length === 0 || Array.isArray(args[0])) {
|
|
62
|
+
options = args[1] || {};
|
|
63
|
+
pipeline = args[0] || [];
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
options = {};
|
|
67
|
+
pipeline = args || [];
|
|
68
|
+
}
|
|
69
|
+
this._emitCollectionApiCall('aggregate', { options, pipeline });
|
|
70
|
+
const { aggOptions, dbOptions, explain } = (0, helpers_1.adaptAggregateOptions)(options);
|
|
71
|
+
const providerCursor = this._mongo._serviceProvider.aggregate(this._database._name, this._name, pipeline, { ...await this._database._baseOptions(), ...aggOptions }, dbOptions);
|
|
72
|
+
const cursor = new index_1.AggregationCursor(this._mongo, providerCursor);
|
|
73
|
+
if (explain) {
|
|
74
|
+
return await cursor.explain(explain);
|
|
75
|
+
}
|
|
76
|
+
else if ((0, helpers_1.shouldRunAggregationImmediately)(pipeline)) {
|
|
77
|
+
await cursor.hasNext();
|
|
78
|
+
}
|
|
79
|
+
this._mongo._instanceState.currentCursor = cursor;
|
|
80
|
+
return cursor;
|
|
81
|
+
}
|
|
82
|
+
async bulkWrite(operations, options = {}) {
|
|
83
|
+
this._emitCollectionApiCall('bulkWrite', { options });
|
|
84
|
+
const result = await this._mongo._serviceProvider.bulkWrite(this._database._name, this._name, operations, { ...await this._database._baseOptions(), ...options });
|
|
85
|
+
return new index_1.BulkWriteResult(!!result.ok, result.insertedCount, result.insertedIds, result.matchedCount, result.modifiedCount, result.deletedCount, result.upsertedCount, result.upsertedIds);
|
|
86
|
+
}
|
|
87
|
+
async count(query = {}, options = {}) {
|
|
88
|
+
await this._instanceState.printDeprecationWarning('Collection.count() is deprecated. Use countDocuments or estimatedDocumentCount.');
|
|
89
|
+
this._emitCollectionApiCall('count', { query, options });
|
|
90
|
+
return this._mongo._serviceProvider.count(this._database._name, this._name, query, { ...await this._database._baseOptions(), ...options });
|
|
91
|
+
}
|
|
92
|
+
async countDocuments(query, options = {}) {
|
|
93
|
+
this._emitCollectionApiCall('countDocuments', { query, options });
|
|
94
|
+
return this._mongo._serviceProvider.countDocuments(this._database._name, this._name, query, { ...await this._database._baseOptions(), ...options });
|
|
95
|
+
}
|
|
96
|
+
async deleteMany(filter, options = {}) {
|
|
97
|
+
(0, helpers_1.assertArgsDefinedType)([filter], [true], 'Collection.deleteMany');
|
|
98
|
+
this._emitCollectionApiCall('deleteMany', { filter, options });
|
|
99
|
+
const result = await this._mongo._serviceProvider.deleteMany(this._database._name, this._name, filter, { ...await this._database._baseOptions(), ...options });
|
|
100
|
+
if (options.explain) {
|
|
101
|
+
return (0, helpers_1.markAsExplainOutput)(result);
|
|
102
|
+
}
|
|
103
|
+
return new index_1.DeleteResult(!!result.acknowledged, result.deletedCount);
|
|
104
|
+
}
|
|
105
|
+
async deleteOne(filter, options = {}) {
|
|
106
|
+
(0, helpers_1.assertArgsDefinedType)([filter], [true], 'Collection.deleteOne');
|
|
107
|
+
this._emitCollectionApiCall('deleteOne', { filter, options });
|
|
108
|
+
const result = await this._mongo._serviceProvider.deleteOne(this._database._name, this._name, filter, { ...await this._database._baseOptions(), ...options });
|
|
109
|
+
if (options.explain) {
|
|
110
|
+
return (0, helpers_1.markAsExplainOutput)(result);
|
|
111
|
+
}
|
|
112
|
+
return new index_1.DeleteResult(!!result.acknowledged, result.deletedCount);
|
|
113
|
+
}
|
|
114
|
+
async distinct(field, query, options = {}) {
|
|
115
|
+
this._emitCollectionApiCall('distinct', { field, query, options });
|
|
116
|
+
return (0, helpers_1.maybeMarkAsExplainOutput)(await this._mongo._serviceProvider.distinct(this._database._name, this._name, field, query, { ...await this._database._baseOptions(), ...options }), options);
|
|
117
|
+
}
|
|
118
|
+
async estimatedDocumentCount(options = {}) {
|
|
119
|
+
this._emitCollectionApiCall('estimatedDocumentCount', { options });
|
|
120
|
+
return this._mongo._serviceProvider.estimatedDocumentCount(this._database._name, this._name, { ...await this._database._baseOptions(), ...options });
|
|
121
|
+
}
|
|
122
|
+
async find(query, projection, options = {}) {
|
|
123
|
+
if (projection) {
|
|
124
|
+
options.projection = projection;
|
|
125
|
+
}
|
|
126
|
+
this._emitCollectionApiCall('find', { query, options });
|
|
127
|
+
const cursor = new index_1.Cursor(this._mongo, this._mongo._serviceProvider.find(this._database._name, this._name, query, { ...await this._database._baseOptions(), ...options }));
|
|
128
|
+
this._mongo._instanceState.currentCursor = cursor;
|
|
129
|
+
return cursor;
|
|
130
|
+
}
|
|
131
|
+
async findAndModify(options) {
|
|
132
|
+
(0, helpers_1.assertArgsDefinedType)([options], [true], 'Collection.findAndModify');
|
|
133
|
+
(0, helpers_1.assertKeysDefined)(options, ['query']);
|
|
134
|
+
this._emitCollectionApiCall('findAndModify', { options: { ...options, update: !!options.update } });
|
|
135
|
+
const reducedOptions = { ...options };
|
|
136
|
+
delete reducedOptions.query;
|
|
137
|
+
delete reducedOptions.update;
|
|
138
|
+
if (options.remove) {
|
|
139
|
+
return this.findOneAndDelete(options.query, reducedOptions);
|
|
140
|
+
}
|
|
141
|
+
const { update } = options;
|
|
142
|
+
if (!update) {
|
|
143
|
+
throw new errors_1.MongoshInvalidInputError('Must specify options.update or options.remove', errors_1.CommonErrors.InvalidArgument);
|
|
144
|
+
}
|
|
145
|
+
if (Array.isArray(update) || Object.keys(update).some(key => key.startsWith('$'))) {
|
|
146
|
+
return this.findOneAndUpdate(options.query, update, reducedOptions);
|
|
147
|
+
}
|
|
148
|
+
return this.findOneAndReplace(options.query, update, reducedOptions);
|
|
149
|
+
}
|
|
150
|
+
async findOne(query = {}, projection, options = {}) {
|
|
151
|
+
if (projection) {
|
|
152
|
+
options.projection = projection;
|
|
153
|
+
}
|
|
154
|
+
this._emitCollectionApiCall('findOne', { query, options });
|
|
155
|
+
return new index_1.Cursor(this._mongo, this._mongo._serviceProvider.find(this._database._name, this._name, query, { ...await this._database._baseOptions(), ...options })).limit(1).tryNext();
|
|
156
|
+
}
|
|
157
|
+
async renameCollection(newName, dropTarget) {
|
|
158
|
+
(0, helpers_1.assertArgsDefinedType)([newName], ['string'], 'Collection.renameCollection');
|
|
159
|
+
this._emitCollectionApiCall('renameCollection', { newName, dropTarget });
|
|
160
|
+
try {
|
|
161
|
+
await this._mongo._serviceProvider.renameCollection(this._database._name, this._name, newName, { ...await this._database._baseOptions(), dropTarget: !!dropTarget });
|
|
162
|
+
return {
|
|
163
|
+
ok: 1
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
catch (e) {
|
|
167
|
+
if ((e === null || e === void 0 ? void 0 : e.name) === 'MongoError') {
|
|
168
|
+
return {
|
|
169
|
+
ok: 0,
|
|
170
|
+
errmsg: e.errmsg,
|
|
171
|
+
code: e.code,
|
|
172
|
+
codeName: e.codeName
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
throw e;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async findOneAndDelete(filter, options = {}) {
|
|
179
|
+
(0, helpers_1.assertArgsDefinedType)([filter], [true], 'Collection.findOneAndDelete');
|
|
180
|
+
this._emitCollectionApiCall('findOneAndDelete', { filter, options });
|
|
181
|
+
const result = await this._mongo._serviceProvider.findOneAndDelete(this._database._name, this._name, filter, { ...await this._database._baseOptions(), ...options });
|
|
182
|
+
if (options.explain) {
|
|
183
|
+
return (0, helpers_1.markAsExplainOutput)(result);
|
|
184
|
+
}
|
|
185
|
+
return result.value;
|
|
186
|
+
}
|
|
187
|
+
async findOneAndReplace(filter, replacement, options = {}) {
|
|
188
|
+
(0, helpers_1.assertArgsDefinedType)([filter], [true], 'Collection.findOneAndReplace');
|
|
189
|
+
const findOneAndReplaceOptions = (0, helpers_1.processFindAndModifyOptions)({
|
|
190
|
+
...await this._database._baseOptions(),
|
|
191
|
+
...options
|
|
192
|
+
});
|
|
193
|
+
this._emitCollectionApiCall('findOneAndReplace', { filter, findOneAndReplaceOptions });
|
|
194
|
+
const result = await this._mongo._serviceProvider.findOneAndReplace(this._database._name, this._name, filter, replacement, findOneAndReplaceOptions);
|
|
195
|
+
if (options.explain) {
|
|
196
|
+
return (0, helpers_1.markAsExplainOutput)(result);
|
|
197
|
+
}
|
|
198
|
+
return result.value;
|
|
199
|
+
}
|
|
200
|
+
async findOneAndUpdate(filter, update, options = {}) {
|
|
201
|
+
(0, helpers_1.assertArgsDefinedType)([filter], [true], 'Collection.findOneAndUpdate');
|
|
202
|
+
const findOneAndUpdateOptions = (0, helpers_1.processFindAndModifyOptions)({
|
|
203
|
+
...await this._database._baseOptions(),
|
|
204
|
+
...options
|
|
205
|
+
});
|
|
206
|
+
this._emitCollectionApiCall('findOneAndUpdate', { filter, findOneAndUpdateOptions });
|
|
207
|
+
const result = await this._mongo._serviceProvider.findOneAndUpdate(this._database._name, this._name, filter, update, findOneAndUpdateOptions);
|
|
208
|
+
if (options.explain) {
|
|
209
|
+
return (0, helpers_1.markAsExplainOutput)(result);
|
|
210
|
+
}
|
|
211
|
+
return result.value;
|
|
212
|
+
}
|
|
213
|
+
async insert(docs, options = {}) {
|
|
214
|
+
await this._instanceState.printDeprecationWarning('Collection.insert() is deprecated. Use insertOne, insertMany, or bulkWrite.');
|
|
215
|
+
(0, helpers_1.assertArgsDefinedType)([docs], [true], 'Collection.insert');
|
|
216
|
+
const docsToInsert = Array.isArray(docs) ? docs.map((doc) => ({ ...doc })) : [{ ...docs }];
|
|
217
|
+
this._emitCollectionApiCall('insert', { options });
|
|
218
|
+
const result = await this._mongo._serviceProvider.insertMany(this._database._name, this._name, docsToInsert, { ...await this._database._baseOptions(), ...options });
|
|
219
|
+
return new index_1.InsertManyResult(!!result.acknowledged, result.insertedIds);
|
|
220
|
+
}
|
|
221
|
+
async insertMany(docs, options = {}) {
|
|
222
|
+
(0, helpers_1.assertArgsDefinedType)([docs], [true], 'Collection.insertMany');
|
|
223
|
+
const docsToInsert = Array.isArray(docs) ? docs.map((doc) => ({ ...doc })) : docs;
|
|
224
|
+
this._emitCollectionApiCall('insertMany', { options });
|
|
225
|
+
const result = await this._mongo._serviceProvider.insertMany(this._database._name, this._name, docsToInsert, { ...await this._database._baseOptions(), ...options });
|
|
226
|
+
return new index_1.InsertManyResult(!!result.acknowledged, result.insertedIds);
|
|
227
|
+
}
|
|
228
|
+
async insertOne(doc, options = {}) {
|
|
229
|
+
(0, helpers_1.assertArgsDefinedType)([doc], [true], 'Collection.insertOne');
|
|
230
|
+
this._emitCollectionApiCall('insertOne', { options });
|
|
231
|
+
const result = await this._mongo._serviceProvider.insertOne(this._database._name, this._name, { ...doc }, { ...await this._database._baseOptions(), ...options });
|
|
232
|
+
return new index_1.InsertOneResult(!!result.acknowledged, result.insertedId);
|
|
233
|
+
}
|
|
234
|
+
async isCapped() {
|
|
235
|
+
this._emitCollectionApiCall('isCapped');
|
|
236
|
+
return this._mongo._serviceProvider.isCapped(this._database._name, this._name);
|
|
237
|
+
}
|
|
238
|
+
async remove(query, options = {}) {
|
|
239
|
+
await this._instanceState.printDeprecationWarning('Collection.remove() is deprecated. Use deleteOne, deleteMany, findOneAndDelete, or bulkWrite.');
|
|
240
|
+
(0, helpers_1.assertArgsDefinedType)([query], [true], 'Collection.remove');
|
|
241
|
+
const removeOptions = (0, helpers_1.processRemoveOptions)(options);
|
|
242
|
+
const method = removeOptions.justOne ? 'deleteOne' : 'deleteMany';
|
|
243
|
+
delete removeOptions.justOne;
|
|
244
|
+
this._emitCollectionApiCall('remove', { query, removeOptions });
|
|
245
|
+
const result = await this._mongo._serviceProvider[method](this._database._name, this._name, query, { ...await this._database._baseOptions(), ...removeOptions });
|
|
246
|
+
if (removeOptions.explain) {
|
|
247
|
+
return (0, helpers_1.markAsExplainOutput)(result);
|
|
248
|
+
}
|
|
249
|
+
return new index_1.DeleteResult(!!result.acknowledged, result.deletedCount);
|
|
250
|
+
}
|
|
251
|
+
save() {
|
|
252
|
+
throw new errors_1.MongoshInvalidInputError('Collection.save() is deprecated. Use insertOne, insertMany, updateOne, or updateMany.');
|
|
253
|
+
}
|
|
254
|
+
async replaceOne(filter, replacement, options = {}) {
|
|
255
|
+
(0, helpers_1.assertArgsDefinedType)([filter], [true], 'Collection.replaceOne');
|
|
256
|
+
this._emitCollectionApiCall('replaceOne', { filter, options });
|
|
257
|
+
const result = await this._mongo._serviceProvider.replaceOne(this._database._name, this._name, filter, replacement, { ...await this._database._baseOptions(), ...options });
|
|
258
|
+
return new index_1.UpdateResult(!!result.acknowledged, result.matchedCount, result.modifiedCount, result.upsertedCount, result.upsertedId);
|
|
259
|
+
}
|
|
260
|
+
async update(filter, update, options = {}) {
|
|
261
|
+
await this._instanceState.printDeprecationWarning('Collection.update() is deprecated. Use updateOne, updateMany, or bulkWrite.');
|
|
262
|
+
(0, helpers_1.assertArgsDefinedType)([filter, update], [true, true], 'Collection.update');
|
|
263
|
+
this._emitCollectionApiCall('update', { filter, options });
|
|
264
|
+
let result;
|
|
265
|
+
if (options.multi) {
|
|
266
|
+
result = await this._mongo._serviceProvider.updateMany(this._database._name, this._name, filter, update, { ...await this._database._baseOptions(), ...options });
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
result = await this._mongo._serviceProvider.updateOne(this._database._name, this._name, filter, update, { ...await this._database._baseOptions(), ...options });
|
|
270
|
+
}
|
|
271
|
+
if (options.explain) {
|
|
272
|
+
return (0, helpers_1.markAsExplainOutput)(result);
|
|
273
|
+
}
|
|
274
|
+
return new index_1.UpdateResult(!!result.acknowledged, result.matchedCount, result.modifiedCount, result.upsertedCount, result.upsertedId);
|
|
275
|
+
}
|
|
276
|
+
async updateMany(filter, update, options = {}) {
|
|
277
|
+
(0, helpers_1.assertArgsDefinedType)([filter], [true], 'Collection.updateMany');
|
|
278
|
+
this._emitCollectionApiCall('updateMany', { filter, options });
|
|
279
|
+
const result = await this._mongo._serviceProvider.updateMany(this._database._name, this._name, filter, update, { ...await this._database._baseOptions(), ...options });
|
|
280
|
+
if (options.explain) {
|
|
281
|
+
return (0, helpers_1.markAsExplainOutput)(result);
|
|
282
|
+
}
|
|
283
|
+
return new index_1.UpdateResult(!!result.acknowledged, result.matchedCount, result.modifiedCount, result.upsertedCount, result.upsertedId);
|
|
284
|
+
}
|
|
285
|
+
async updateOne(filter, update, options = {}) {
|
|
286
|
+
(0, helpers_1.assertArgsDefinedType)([filter], [true], 'Collection.updateOne');
|
|
287
|
+
this._emitCollectionApiCall('updateOne', { filter, options });
|
|
288
|
+
const result = await this._mongo._serviceProvider.updateOne(this._database._name, this._name, filter, update, { ...await this._database._baseOptions(), ...options });
|
|
289
|
+
if (options.explain) {
|
|
290
|
+
return (0, helpers_1.markAsExplainOutput)(result);
|
|
291
|
+
}
|
|
292
|
+
return new index_1.UpdateResult(!!result.acknowledged, result.matchedCount, result.modifiedCount, result.upsertedCount, result.upsertedId);
|
|
293
|
+
}
|
|
294
|
+
async convertToCapped(size) {
|
|
295
|
+
this._emitCollectionApiCall('convertToCapped', { size });
|
|
296
|
+
return await this._database._runCommand({
|
|
297
|
+
convertToCapped: this._name,
|
|
298
|
+
size
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
async _createIndexes(keyPatterns, options = {}, commitQuorum) {
|
|
302
|
+
(0, helpers_1.assertArgsDefinedType)([keyPatterns], [true], 'Collection.createIndexes');
|
|
303
|
+
if (typeof options !== 'object' || Array.isArray(options)) {
|
|
304
|
+
throw new errors_1.MongoshInvalidInputError('The "options" argument must be an object.', errors_1.CommonErrors.InvalidArgument);
|
|
305
|
+
}
|
|
306
|
+
const specs = keyPatterns.map((pattern) => ({
|
|
307
|
+
...options, key: pattern
|
|
308
|
+
}));
|
|
309
|
+
const createIndexesOptions = { ...await this._database._baseOptions(), ...options };
|
|
310
|
+
if (undefined !== commitQuorum) {
|
|
311
|
+
createIndexesOptions.commitQuorum = commitQuorum;
|
|
312
|
+
}
|
|
313
|
+
return await this._mongo._serviceProvider.createIndexes(this._database._name, this._name, specs, createIndexesOptions);
|
|
314
|
+
}
|
|
315
|
+
async createIndexes(keyPatterns, options = {}, commitQuorum) {
|
|
316
|
+
const specs = keyPatterns.map((pattern) => ({
|
|
317
|
+
...options, key: pattern
|
|
318
|
+
}));
|
|
319
|
+
this._emitCollectionApiCall('createIndexes', { specs });
|
|
320
|
+
return this._createIndexes(keyPatterns, options, commitQuorum);
|
|
321
|
+
}
|
|
322
|
+
async createIndex(keys, options = {}, commitQuorum) {
|
|
323
|
+
(0, helpers_1.assertArgsDefinedType)([keys], [true], 'Collection.createIndex');
|
|
324
|
+
if (typeof options !== 'object' || Array.isArray(options)) {
|
|
325
|
+
throw new errors_1.MongoshInvalidInputError('The "options" argument must be an object.', errors_1.CommonErrors.InvalidArgument);
|
|
326
|
+
}
|
|
327
|
+
this._emitCollectionApiCall('createIndex', { keys, options });
|
|
328
|
+
const names = await this._createIndexes([keys], options, commitQuorum);
|
|
329
|
+
if (!Array.isArray(names) || names.length !== 1) {
|
|
330
|
+
throw new errors_1.MongoshInternalError(`Expected createIndexes() to return array of length 1, saw ${names}`);
|
|
331
|
+
}
|
|
332
|
+
return names[0];
|
|
333
|
+
}
|
|
334
|
+
async ensureIndex(keys, options = {}, commitQuorum) {
|
|
335
|
+
this._emitCollectionApiCall('ensureIndex', { keys, options });
|
|
336
|
+
return await this._createIndexes([keys], options, commitQuorum);
|
|
337
|
+
}
|
|
338
|
+
async getIndexes() {
|
|
339
|
+
this._emitCollectionApiCall('getIndexes');
|
|
340
|
+
return await this._mongo._serviceProvider.getIndexes(this._database._name, this._name, await this._database._baseOptions());
|
|
341
|
+
}
|
|
342
|
+
async getIndexSpecs() {
|
|
343
|
+
this._emitCollectionApiCall('getIndexSpecs');
|
|
344
|
+
return await this._mongo._serviceProvider.getIndexes(this._database._name, this._name, await this._database._baseOptions());
|
|
345
|
+
}
|
|
346
|
+
async getIndices() {
|
|
347
|
+
this._emitCollectionApiCall('getIndices');
|
|
348
|
+
return await this._mongo._serviceProvider.getIndexes(this._database._name, this._name, await this._database._baseOptions());
|
|
349
|
+
}
|
|
350
|
+
async getIndexKeys() {
|
|
351
|
+
this._emitCollectionApiCall('getIndexKeys');
|
|
352
|
+
const indexes = await this._mongo._serviceProvider.getIndexes(this._database._name, this._name, await this._database._baseOptions());
|
|
353
|
+
return indexes.map(i => i.key);
|
|
354
|
+
}
|
|
355
|
+
async dropIndexes(indexes = '*') {
|
|
356
|
+
this._emitCollectionApiCall('dropIndexes', { indexes });
|
|
357
|
+
try {
|
|
358
|
+
return await this._database._runCommand({
|
|
359
|
+
dropIndexes: this._name,
|
|
360
|
+
index: indexes,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
catch (error) {
|
|
364
|
+
if (((error === null || error === void 0 ? void 0 : error.codeName) === 'IndexNotFound' || (error === null || error === void 0 ? void 0 : error.codeName) === undefined) &&
|
|
365
|
+
((error === null || error === void 0 ? void 0 : error.errmsg) === 'invalid index name spec' || (error === null || error === void 0 ? void 0 : error.errmsg) === undefined) &&
|
|
366
|
+
Array.isArray(indexes) &&
|
|
367
|
+
indexes.length > 0 &&
|
|
368
|
+
(await this._database.version()).match(/^4\.0\./)) {
|
|
369
|
+
const all = await Promise.all(indexes.map(async (index) => await this.dropIndexes(index)));
|
|
370
|
+
const errored = all.find(result => !result.ok);
|
|
371
|
+
if (errored)
|
|
372
|
+
return errored;
|
|
373
|
+
return all.sort((a, b) => b.nIndexesWas - a.nIndexesWas)[0];
|
|
374
|
+
}
|
|
375
|
+
if ((error === null || error === void 0 ? void 0 : error.codeName) === 'IndexNotFound') {
|
|
376
|
+
return {
|
|
377
|
+
ok: error.ok,
|
|
378
|
+
errmsg: error.errmsg,
|
|
379
|
+
code: error.code,
|
|
380
|
+
codeName: error.codeName
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
throw error;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
async dropIndex(index) {
|
|
387
|
+
(0, helpers_1.assertArgsDefinedType)([index], [true], 'Collection.dropIndex');
|
|
388
|
+
this._emitCollectionApiCall('dropIndex', { index });
|
|
389
|
+
if (index === '*') {
|
|
390
|
+
throw new errors_1.MongoshInvalidInputError('To drop indexes in the collection using \'*\', use db.collection.dropIndexes().', errors_1.CommonErrors.InvalidArgument);
|
|
391
|
+
}
|
|
392
|
+
if (Array.isArray(index)) {
|
|
393
|
+
throw new errors_1.MongoshInvalidInputError('The index to drop must be either the index name or the index specification document.', errors_1.CommonErrors.InvalidArgument);
|
|
394
|
+
}
|
|
395
|
+
return this.dropIndexes(index);
|
|
396
|
+
}
|
|
397
|
+
async totalIndexSize(...args) {
|
|
398
|
+
this._emitCollectionApiCall('totalIndexSize');
|
|
399
|
+
if (args.length) {
|
|
400
|
+
throw new errors_1.MongoshInvalidInputError('"totalIndexSize" takes no argument. Use db.collection.stats to get detailed information.', errors_1.CommonErrors.InvalidArgument);
|
|
401
|
+
}
|
|
402
|
+
const stats = await this._mongo._serviceProvider.stats(this._database._name, this._name, await this._database._baseOptions());
|
|
403
|
+
return stats.totalIndexSize;
|
|
404
|
+
}
|
|
405
|
+
async reIndex() {
|
|
406
|
+
this._emitCollectionApiCall('reIndex');
|
|
407
|
+
return await this._database._runCommand({
|
|
408
|
+
reIndex: this._name
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
getDB() {
|
|
412
|
+
this._emitCollectionApiCall('getDB');
|
|
413
|
+
return this._database;
|
|
414
|
+
}
|
|
415
|
+
getMongo() {
|
|
416
|
+
this._emitCollectionApiCall('getMongo');
|
|
417
|
+
return this._mongo;
|
|
418
|
+
}
|
|
419
|
+
async dataSize() {
|
|
420
|
+
this._emitCollectionApiCall('dataSize');
|
|
421
|
+
const stats = await this._mongo._serviceProvider.stats(this._database._name, this._name, await this._database._baseOptions());
|
|
422
|
+
return stats.size;
|
|
423
|
+
}
|
|
424
|
+
async storageSize() {
|
|
425
|
+
this._emitCollectionApiCall('storageSize');
|
|
426
|
+
const stats = await this._mongo._serviceProvider.stats(this._database._name, this._name, await this._database._baseOptions());
|
|
427
|
+
return stats.storageSize;
|
|
428
|
+
}
|
|
429
|
+
async totalSize() {
|
|
430
|
+
this._emitCollectionApiCall('totalSize');
|
|
431
|
+
const stats = await this._mongo._serviceProvider.stats(this._database._name, this._name, await this._database._baseOptions());
|
|
432
|
+
return (Number(stats.storageSize) || 0) + (Number(stats.totalIndexSize) || 0);
|
|
433
|
+
}
|
|
434
|
+
async drop() {
|
|
435
|
+
this._emitCollectionApiCall('drop');
|
|
436
|
+
try {
|
|
437
|
+
return await this._mongo._serviceProvider.dropCollection(this._database._name, this._name, await this._database._baseOptions());
|
|
438
|
+
}
|
|
439
|
+
catch (error) {
|
|
440
|
+
if ((error === null || error === void 0 ? void 0 : error.codeName) === 'NamespaceNotFound') {
|
|
441
|
+
this._mongo._instanceState.messageBus.emit('mongosh:warn', {
|
|
442
|
+
method: 'drop',
|
|
443
|
+
class: 'Collection',
|
|
444
|
+
message: `Namespace not found: ${this._name}`
|
|
445
|
+
});
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
throw error;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
async exists() {
|
|
452
|
+
this._emitCollectionApiCall('exists');
|
|
453
|
+
const collectionInfos = await this._mongo._serviceProvider.listCollections(this._database._name, {
|
|
454
|
+
name: this._name
|
|
455
|
+
}, await this._database._baseOptions());
|
|
456
|
+
return collectionInfos[0] || null;
|
|
457
|
+
}
|
|
458
|
+
getFullName() {
|
|
459
|
+
this._emitCollectionApiCall('getFullName');
|
|
460
|
+
return `${this._database._name}.${this._name}`;
|
|
461
|
+
}
|
|
462
|
+
getName() {
|
|
463
|
+
this._emitCollectionApiCall('getName');
|
|
464
|
+
return `${this._name}`;
|
|
465
|
+
}
|
|
466
|
+
async runCommand(commandName, options) {
|
|
467
|
+
(0, helpers_1.assertArgsDefinedType)([commandName], [['string', 'object']], 'Collection.runCommand');
|
|
468
|
+
if (options) {
|
|
469
|
+
if (typeof commandName !== 'string') {
|
|
470
|
+
throw new errors_1.MongoshInvalidInputError('Collection.runCommand takes a command string as its first arugment', errors_1.CommonErrors.InvalidArgument);
|
|
471
|
+
}
|
|
472
|
+
else if (commandName in options) {
|
|
473
|
+
throw new errors_1.MongoshInvalidInputError('The "commandName" argument cannot be passed as an option to "runCommand".', errors_1.CommonErrors.InvalidArgument);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
const hiddenCommands = new RegExp(history_1.HIDDEN_COMMANDS);
|
|
477
|
+
if (typeof commandName === 'string' && !hiddenCommands.test(commandName)) {
|
|
478
|
+
this._emitCollectionApiCall('runCommand', { commandName });
|
|
479
|
+
}
|
|
480
|
+
const cmd = typeof commandName === 'string' ? {
|
|
481
|
+
[commandName]: this._name,
|
|
482
|
+
...options
|
|
483
|
+
} : commandName;
|
|
484
|
+
return await this._database._runCommand(cmd);
|
|
485
|
+
}
|
|
486
|
+
explain(verbosity = 'queryPlanner') {
|
|
487
|
+
verbosity = (0, helpers_1.validateExplainableVerbosity)(verbosity);
|
|
488
|
+
this._emitCollectionApiCall('explain', { verbosity });
|
|
489
|
+
return new index_1.Explainable(this._mongo, this, verbosity);
|
|
490
|
+
}
|
|
491
|
+
async stats(originalOptions = {}) {
|
|
492
|
+
var _a;
|
|
493
|
+
const options = typeof originalOptions === 'number' ? { scale: originalOptions } : originalOptions;
|
|
494
|
+
if (options.indexDetailsKey && options.indexDetailsName) {
|
|
495
|
+
throw new errors_1.MongoshInvalidInputError('Cannot filter indexDetails on both indexDetailsKey and indexDetailsName', errors_1.CommonErrors.InvalidArgument);
|
|
496
|
+
}
|
|
497
|
+
if (options.indexDetailsKey && typeof options.indexDetailsKey !== 'object') {
|
|
498
|
+
throw new errors_1.MongoshInvalidInputError(`Expected options.indexDetailsKey to be a document, got ${typeof options.indexDetailsKey}`, errors_1.CommonErrors.InvalidArgument);
|
|
499
|
+
}
|
|
500
|
+
if (options.indexDetailsName && typeof options.indexDetailsName !== 'string') {
|
|
501
|
+
throw new errors_1.MongoshInvalidInputError(`Expected options.indexDetailsName to be a string, got ${typeof options.indexDetailsName}`, errors_1.CommonErrors.InvalidArgument);
|
|
502
|
+
}
|
|
503
|
+
options.scale = options.scale || 1;
|
|
504
|
+
options.indexDetails = options.indexDetails || false;
|
|
505
|
+
this._emitCollectionApiCall('stats', { options });
|
|
506
|
+
const result = await this._database._runCommand({
|
|
507
|
+
collStats: this._name, scale: options.scale
|
|
508
|
+
});
|
|
509
|
+
if (!result) {
|
|
510
|
+
throw new errors_1.MongoshRuntimeError(`Error running collStats command on ${this.getFullName()}`, errors_1.CommonErrors.CommandFailed);
|
|
511
|
+
}
|
|
512
|
+
let filterIndexName = options.indexDetailsName;
|
|
513
|
+
if (!filterIndexName && options.indexDetailsKey) {
|
|
514
|
+
const indexes = await this._mongo._serviceProvider.getIndexes(this._database._name, this._name, await this._database._baseOptions());
|
|
515
|
+
indexes.forEach((spec) => {
|
|
516
|
+
if (JSON.stringify(spec.key) === JSON.stringify(options.indexDetailsKey)) {
|
|
517
|
+
filterIndexName = spec.name;
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
const updateStats = (stats) => {
|
|
522
|
+
if (!stats.indexDetails) {
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
if (!options.indexDetails) {
|
|
526
|
+
delete stats.indexDetails;
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
if (!filterIndexName) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
for (const key of Object.keys(stats.indexDetails)) {
|
|
533
|
+
if (key === filterIndexName) {
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
delete stats.indexDetails[key];
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
updateStats(result);
|
|
540
|
+
for (const shardName of Object.keys((_a = result.shards) !== null && _a !== void 0 ? _a : {})) {
|
|
541
|
+
updateStats(result.shards[shardName]);
|
|
542
|
+
}
|
|
543
|
+
return result;
|
|
544
|
+
}
|
|
545
|
+
async latencyStats(options = {}) {
|
|
546
|
+
this._emitCollectionApiCall('latencyStats', { options });
|
|
547
|
+
const pipeline = [{ $collStats: { latencyStats: options } }];
|
|
548
|
+
const providerCursor = this._mongo._serviceProvider.aggregate(this._database._name, this._name, pipeline, await this._database._baseOptions());
|
|
549
|
+
return await providerCursor.toArray();
|
|
550
|
+
}
|
|
551
|
+
async initializeOrderedBulkOp() {
|
|
552
|
+
this._emitCollectionApiCall('initializeOrderedBulkOp');
|
|
553
|
+
const innerBulk = await this._mongo._serviceProvider.initializeBulkOp(this._database._name, this._name, true, await this._database._baseOptions());
|
|
554
|
+
return new bulk_1.default(this, innerBulk, true);
|
|
555
|
+
}
|
|
556
|
+
async initializeUnorderedBulkOp() {
|
|
557
|
+
this._emitCollectionApiCall('initializeUnorderedBulkOp');
|
|
558
|
+
const innerBulk = await this._mongo._serviceProvider.initializeBulkOp(this._database._name, this._name, false, await this._database._baseOptions());
|
|
559
|
+
return new bulk_1.default(this, innerBulk);
|
|
560
|
+
}
|
|
561
|
+
getPlanCache() {
|
|
562
|
+
this._emitCollectionApiCall('getPlanCache');
|
|
563
|
+
return new plan_cache_1.default(this);
|
|
564
|
+
}
|
|
565
|
+
async mapReduce(map, reduce, optionsOrOutString) {
|
|
566
|
+
await this._instanceState.printDeprecationWarning('Collection.mapReduce() is deprecated. Use an aggregation instead.\nSee https://docs.mongodb.com/manual/core/map-reduce for details.');
|
|
567
|
+
(0, helpers_1.assertArgsDefinedType)([map, reduce, optionsOrOutString], [true, true, true], 'Collection.mapReduce');
|
|
568
|
+
this._emitCollectionApiCall('mapReduce', { map, reduce, out: optionsOrOutString });
|
|
569
|
+
let cmd = {
|
|
570
|
+
mapReduce: this._name,
|
|
571
|
+
map: map,
|
|
572
|
+
reduce: reduce,
|
|
573
|
+
...(0, helpers_1.processMapReduceOptions)(optionsOrOutString)
|
|
574
|
+
};
|
|
575
|
+
if (cmd.explain) {
|
|
576
|
+
const verbosity = cmd.explain;
|
|
577
|
+
delete cmd.explain;
|
|
578
|
+
cmd = {
|
|
579
|
+
explain: cmd,
|
|
580
|
+
verbosity
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
return await this._database._runCommand(cmd);
|
|
584
|
+
}
|
|
585
|
+
async validate(options = false) {
|
|
586
|
+
this._emitCollectionApiCall('validate', { options });
|
|
587
|
+
if (typeof options === 'boolean') {
|
|
588
|
+
options = { full: options };
|
|
589
|
+
}
|
|
590
|
+
return await this._database._runCommand({
|
|
591
|
+
validate: this._name,
|
|
592
|
+
...options
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
async getShardVersion() {
|
|
596
|
+
this._emitCollectionApiCall('getShardVersion', {});
|
|
597
|
+
return await this._database._runAdminCommand({
|
|
598
|
+
getShardVersion: `${this._database._name}.${this._name}`
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
async getShardDistribution() {
|
|
602
|
+
var _a;
|
|
603
|
+
this._emitCollectionApiCall('getShardDistribution', {});
|
|
604
|
+
const result = {};
|
|
605
|
+
const config = this._mongo.getDB('config');
|
|
606
|
+
const ns = `${this._database._name}.${this._name}`;
|
|
607
|
+
const configCollectionsInfo = await config.getCollection('collections').findOne({
|
|
608
|
+
_id: ns,
|
|
609
|
+
dropped: { $ne: true }
|
|
610
|
+
});
|
|
611
|
+
if (!configCollectionsInfo) {
|
|
612
|
+
throw new errors_1.MongoshInvalidInputError(`Collection ${this._name} is not sharded`, error_codes_1.ShellApiErrors.NotConnectedToShardedCluster);
|
|
613
|
+
}
|
|
614
|
+
const collStats = await (await this.aggregate({ '$collStats': { storageStats: {} } })).toArray();
|
|
615
|
+
const uuid = (_a = configCollectionsInfo === null || configCollectionsInfo === void 0 ? void 0 : configCollectionsInfo.uuid) !== null && _a !== void 0 ? _a : null;
|
|
616
|
+
const totals = { numChunks: 0, size: 0, count: 0 };
|
|
617
|
+
const conciseShardsStats = [];
|
|
618
|
+
await Promise.all(collStats.map((extShardStats) => ((async () => {
|
|
619
|
+
const { shard } = extShardStats;
|
|
620
|
+
const countChunksQuery = uuid ? { $or: [{ uuid }, { ns }], shard } : { ns, shard };
|
|
621
|
+
const [host, numChunks] = await Promise.all([
|
|
622
|
+
config.getCollection('shards').findOne({ _id: extShardStats.shard }),
|
|
623
|
+
config.getCollection('chunks').countDocuments(countChunksQuery)
|
|
624
|
+
]);
|
|
625
|
+
const shardStats = {
|
|
626
|
+
shardId: shard,
|
|
627
|
+
host: host !== null ? host.host : null,
|
|
628
|
+
size: extShardStats.storageStats.size,
|
|
629
|
+
count: extShardStats.storageStats.count,
|
|
630
|
+
numChunks: numChunks,
|
|
631
|
+
avgObjSize: extShardStats.storageStats.avgObjSize
|
|
632
|
+
};
|
|
633
|
+
const key = `Shard ${shardStats.shardId} at ${shardStats.host}`;
|
|
634
|
+
const estChunkData = (shardStats.numChunks === 0) ? 0 : (shardStats.size / shardStats.numChunks);
|
|
635
|
+
const estChunkCount = (shardStats.numChunks === 0) ? 0 : Math.floor(shardStats.count / shardStats.numChunks);
|
|
636
|
+
result[key] = {
|
|
637
|
+
data: (0, helpers_1.dataFormat)(shardStats.size),
|
|
638
|
+
docs: shardStats.count,
|
|
639
|
+
chunks: shardStats.numChunks,
|
|
640
|
+
'estimated data per chunk': (0, helpers_1.dataFormat)(estChunkData),
|
|
641
|
+
'estimated docs per chunk': estChunkCount
|
|
642
|
+
};
|
|
643
|
+
totals.size += shardStats.size;
|
|
644
|
+
totals.count += shardStats.count;
|
|
645
|
+
totals.numChunks += shardStats.numChunks;
|
|
646
|
+
conciseShardsStats.push(shardStats);
|
|
647
|
+
})())));
|
|
648
|
+
const totalValue = {
|
|
649
|
+
data: (0, helpers_1.dataFormat)(totals.size),
|
|
650
|
+
docs: totals.count,
|
|
651
|
+
chunks: totals.numChunks
|
|
652
|
+
};
|
|
653
|
+
for (const shardStats of conciseShardsStats) {
|
|
654
|
+
const estDataPercent = (totals.size === 0) ? 0 : (Math.floor(shardStats.size / totals.size * 10000) / 100);
|
|
655
|
+
const estDocPercent = (totals.count === 0) ? 0 : (Math.floor(shardStats.count / totals.count * 10000) / 100);
|
|
656
|
+
totalValue[`Shard ${shardStats.shardId}`] = [
|
|
657
|
+
`${estDataPercent} % data`,
|
|
658
|
+
`${estDocPercent} % docs in cluster`,
|
|
659
|
+
`${(0, helpers_1.dataFormat)(shardStats.avgObjSize)} avg obj size on shard`
|
|
660
|
+
];
|
|
661
|
+
}
|
|
662
|
+
result.Totals = totalValue;
|
|
663
|
+
return new index_1.CommandResult('StatsResult', result);
|
|
664
|
+
}
|
|
665
|
+
async watch(pipeline = [], options = {}) {
|
|
666
|
+
if (!Array.isArray(pipeline)) {
|
|
667
|
+
options = pipeline;
|
|
668
|
+
pipeline = [];
|
|
669
|
+
}
|
|
670
|
+
this._emitCollectionApiCall('watch', { pipeline, options });
|
|
671
|
+
const cursor = new change_stream_cursor_1.default(this._mongo._serviceProvider.watch(pipeline, {
|
|
672
|
+
...await this._database._baseOptions(),
|
|
673
|
+
...options
|
|
674
|
+
}, {}, this._database._name, this._name), this._name, this._mongo);
|
|
675
|
+
if (!options.resumeAfter && !options.startAfter && !options.startAtOperationTime) {
|
|
676
|
+
await cursor.tryNext();
|
|
677
|
+
}
|
|
678
|
+
this._mongo._instanceState.currentCursor = cursor;
|
|
679
|
+
return cursor;
|
|
680
|
+
}
|
|
681
|
+
async hideIndex(index) {
|
|
682
|
+
this._emitCollectionApiCall('hideIndex');
|
|
683
|
+
return (0, helpers_1.setHideIndex)(this, index, true);
|
|
684
|
+
}
|
|
685
|
+
async unhideIndex(index) {
|
|
686
|
+
this._emitCollectionApiCall('unhideIndex');
|
|
687
|
+
return (0, helpers_1.setHideIndex)(this, index, false);
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
__decorate([
|
|
691
|
+
decorators_1.returnsPromise,
|
|
692
|
+
(0, decorators_1.returnType)('AggregationCursor'),
|
|
693
|
+
(0, decorators_1.apiVersions)([1])
|
|
694
|
+
], Collection.prototype, "aggregate", null);
|
|
695
|
+
__decorate([
|
|
696
|
+
decorators_1.returnsPromise,
|
|
697
|
+
(0, decorators_1.serverVersions)(['3.2.0', enums_1.ServerVersions.latest]),
|
|
698
|
+
(0, decorators_1.apiVersions)([1])
|
|
699
|
+
], Collection.prototype, "bulkWrite", null);
|
|
700
|
+
__decorate([
|
|
701
|
+
decorators_1.returnsPromise,
|
|
702
|
+
decorators_1.deprecated,
|
|
703
|
+
(0, decorators_1.serverVersions)([enums_1.ServerVersions.earliest, '4.0.0']),
|
|
704
|
+
(0, decorators_1.apiVersions)([])
|
|
705
|
+
], Collection.prototype, "count", null);
|
|
706
|
+
__decorate([
|
|
707
|
+
decorators_1.returnsPromise,
|
|
708
|
+
(0, decorators_1.serverVersions)(['4.0.3', enums_1.ServerVersions.latest]),
|
|
709
|
+
(0, decorators_1.apiVersions)([1])
|
|
710
|
+
], Collection.prototype, "countDocuments", null);
|
|
711
|
+
__decorate([
|
|
712
|
+
decorators_1.returnsPromise,
|
|
713
|
+
(0, decorators_1.apiVersions)([1])
|
|
714
|
+
], Collection.prototype, "deleteMany", null);
|
|
715
|
+
__decorate([
|
|
716
|
+
decorators_1.returnsPromise,
|
|
717
|
+
(0, decorators_1.apiVersions)([1])
|
|
718
|
+
], Collection.prototype, "deleteOne", null);
|
|
719
|
+
__decorate([
|
|
720
|
+
decorators_1.returnsPromise,
|
|
721
|
+
(0, decorators_1.apiVersions)([])
|
|
722
|
+
], Collection.prototype, "distinct", null);
|
|
723
|
+
__decorate([
|
|
724
|
+
decorators_1.returnsPromise,
|
|
725
|
+
(0, decorators_1.serverVersions)(['4.0.3', enums_1.ServerVersions.latest]),
|
|
726
|
+
(0, decorators_1.apiVersions)([1])
|
|
727
|
+
], Collection.prototype, "estimatedDocumentCount", null);
|
|
728
|
+
__decorate([
|
|
729
|
+
(0, decorators_1.returnType)('Cursor'),
|
|
730
|
+
(0, decorators_1.apiVersions)([1]),
|
|
731
|
+
decorators_1.returnsPromise
|
|
732
|
+
], Collection.prototype, "find", null);
|
|
733
|
+
__decorate([
|
|
734
|
+
decorators_1.returnsPromise,
|
|
735
|
+
decorators_1.deprecated,
|
|
736
|
+
(0, decorators_1.apiVersions)([1])
|
|
737
|
+
], Collection.prototype, "findAndModify", null);
|
|
738
|
+
__decorate([
|
|
739
|
+
decorators_1.returnsPromise,
|
|
740
|
+
(0, decorators_1.returnType)('Document'),
|
|
741
|
+
(0, decorators_1.apiVersions)([1])
|
|
742
|
+
], Collection.prototype, "findOne", null);
|
|
743
|
+
__decorate([
|
|
744
|
+
decorators_1.returnsPromise,
|
|
745
|
+
(0, decorators_1.apiVersions)([])
|
|
746
|
+
], Collection.prototype, "renameCollection", null);
|
|
747
|
+
__decorate([
|
|
748
|
+
decorators_1.returnsPromise,
|
|
749
|
+
(0, decorators_1.returnType)('Document'),
|
|
750
|
+
(0, decorators_1.serverVersions)(['3.2.0', enums_1.ServerVersions.latest]),
|
|
751
|
+
(0, decorators_1.apiVersions)([1])
|
|
752
|
+
], Collection.prototype, "findOneAndDelete", null);
|
|
753
|
+
__decorate([
|
|
754
|
+
decorators_1.returnsPromise,
|
|
755
|
+
(0, decorators_1.returnType)('Document'),
|
|
756
|
+
(0, decorators_1.serverVersions)(['3.2.0', enums_1.ServerVersions.latest]),
|
|
757
|
+
(0, decorators_1.apiVersions)([1])
|
|
758
|
+
], Collection.prototype, "findOneAndReplace", null);
|
|
759
|
+
__decorate([
|
|
760
|
+
decorators_1.returnsPromise,
|
|
761
|
+
(0, decorators_1.returnType)('Document'),
|
|
762
|
+
(0, decorators_1.serverVersions)(['3.2.0', enums_1.ServerVersions.latest]),
|
|
763
|
+
(0, decorators_1.apiVersions)([1])
|
|
764
|
+
], Collection.prototype, "findOneAndUpdate", null);
|
|
765
|
+
__decorate([
|
|
766
|
+
decorators_1.returnsPromise,
|
|
767
|
+
decorators_1.deprecated,
|
|
768
|
+
(0, decorators_1.serverVersions)([enums_1.ServerVersions.earliest, '3.6.0']),
|
|
769
|
+
(0, decorators_1.apiVersions)([1])
|
|
770
|
+
], Collection.prototype, "insert", null);
|
|
771
|
+
__decorate([
|
|
772
|
+
decorators_1.returnsPromise,
|
|
773
|
+
(0, decorators_1.serverVersions)(['3.2.0', enums_1.ServerVersions.latest]),
|
|
774
|
+
(0, decorators_1.apiVersions)([1])
|
|
775
|
+
], Collection.prototype, "insertMany", null);
|
|
776
|
+
__decorate([
|
|
777
|
+
decorators_1.returnsPromise,
|
|
778
|
+
(0, decorators_1.serverVersions)(['3.2.0', enums_1.ServerVersions.latest]),
|
|
779
|
+
(0, decorators_1.apiVersions)([1])
|
|
780
|
+
], Collection.prototype, "insertOne", null);
|
|
781
|
+
__decorate([
|
|
782
|
+
decorators_1.returnsPromise,
|
|
783
|
+
(0, decorators_1.apiVersions)([1])
|
|
784
|
+
], Collection.prototype, "isCapped", null);
|
|
785
|
+
__decorate([
|
|
786
|
+
decorators_1.returnsPromise,
|
|
787
|
+
decorators_1.deprecated,
|
|
788
|
+
(0, decorators_1.serverVersions)([enums_1.ServerVersions.earliest, '3.2.0']),
|
|
789
|
+
(0, decorators_1.apiVersions)([1])
|
|
790
|
+
], Collection.prototype, "remove", null);
|
|
791
|
+
__decorate([
|
|
792
|
+
decorators_1.deprecated
|
|
793
|
+
], Collection.prototype, "save", null);
|
|
794
|
+
__decorate([
|
|
795
|
+
decorators_1.returnsPromise,
|
|
796
|
+
(0, decorators_1.serverVersions)(['3.2.0', enums_1.ServerVersions.latest]),
|
|
797
|
+
(0, decorators_1.apiVersions)([1])
|
|
798
|
+
], Collection.prototype, "replaceOne", null);
|
|
799
|
+
__decorate([
|
|
800
|
+
decorators_1.returnsPromise,
|
|
801
|
+
decorators_1.deprecated,
|
|
802
|
+
(0, decorators_1.serverVersions)([enums_1.ServerVersions.earliest, '3.2.0']),
|
|
803
|
+
(0, decorators_1.apiVersions)([1])
|
|
804
|
+
], Collection.prototype, "update", null);
|
|
805
|
+
__decorate([
|
|
806
|
+
decorators_1.returnsPromise,
|
|
807
|
+
(0, decorators_1.serverVersions)(['3.2.0', enums_1.ServerVersions.latest]),
|
|
808
|
+
(0, decorators_1.apiVersions)([1])
|
|
809
|
+
], Collection.prototype, "updateMany", null);
|
|
810
|
+
__decorate([
|
|
811
|
+
decorators_1.returnsPromise,
|
|
812
|
+
(0, decorators_1.serverVersions)(['3.2.0', enums_1.ServerVersions.latest]),
|
|
813
|
+
(0, decorators_1.apiVersions)([1])
|
|
814
|
+
], Collection.prototype, "updateOne", null);
|
|
815
|
+
__decorate([
|
|
816
|
+
decorators_1.returnsPromise,
|
|
817
|
+
(0, decorators_1.apiVersions)([])
|
|
818
|
+
], Collection.prototype, "convertToCapped", null);
|
|
819
|
+
__decorate([
|
|
820
|
+
decorators_1.returnsPromise,
|
|
821
|
+
(0, decorators_1.serverVersions)(['3.2.0', enums_1.ServerVersions.latest]),
|
|
822
|
+
(0, decorators_1.apiVersions)([1])
|
|
823
|
+
], Collection.prototype, "createIndexes", null);
|
|
824
|
+
__decorate([
|
|
825
|
+
decorators_1.returnsPromise,
|
|
826
|
+
(0, decorators_1.apiVersions)([1])
|
|
827
|
+
], Collection.prototype, "createIndex", null);
|
|
828
|
+
__decorate([
|
|
829
|
+
decorators_1.returnsPromise,
|
|
830
|
+
(0, decorators_1.apiVersions)([1])
|
|
831
|
+
], Collection.prototype, "ensureIndex", null);
|
|
832
|
+
__decorate([
|
|
833
|
+
decorators_1.returnsPromise,
|
|
834
|
+
(0, decorators_1.serverVersions)(['3.2.0', enums_1.ServerVersions.latest]),
|
|
835
|
+
(0, decorators_1.apiVersions)([1])
|
|
836
|
+
], Collection.prototype, "getIndexes", null);
|
|
837
|
+
__decorate([
|
|
838
|
+
decorators_1.returnsPromise,
|
|
839
|
+
(0, decorators_1.serverVersions)(['3.2.0', enums_1.ServerVersions.latest]),
|
|
840
|
+
(0, decorators_1.apiVersions)([1])
|
|
841
|
+
], Collection.prototype, "getIndexSpecs", null);
|
|
842
|
+
__decorate([
|
|
843
|
+
decorators_1.returnsPromise,
|
|
844
|
+
(0, decorators_1.apiVersions)([1])
|
|
845
|
+
], Collection.prototype, "getIndices", null);
|
|
846
|
+
__decorate([
|
|
847
|
+
decorators_1.returnsPromise,
|
|
848
|
+
(0, decorators_1.serverVersions)(['3.2.0', enums_1.ServerVersions.latest]),
|
|
849
|
+
(0, decorators_1.apiVersions)([1])
|
|
850
|
+
], Collection.prototype, "getIndexKeys", null);
|
|
851
|
+
__decorate([
|
|
852
|
+
decorators_1.returnsPromise,
|
|
853
|
+
(0, decorators_1.apiVersions)([1])
|
|
854
|
+
], Collection.prototype, "dropIndexes", null);
|
|
855
|
+
__decorate([
|
|
856
|
+
decorators_1.returnsPromise,
|
|
857
|
+
(0, decorators_1.apiVersions)([1])
|
|
858
|
+
], Collection.prototype, "dropIndex", null);
|
|
859
|
+
__decorate([
|
|
860
|
+
decorators_1.returnsPromise,
|
|
861
|
+
(0, decorators_1.apiVersions)([])
|
|
862
|
+
], Collection.prototype, "totalIndexSize", null);
|
|
863
|
+
__decorate([
|
|
864
|
+
decorators_1.returnsPromise,
|
|
865
|
+
(0, decorators_1.topologies)([enums_1.Topologies.Standalone]),
|
|
866
|
+
(0, decorators_1.apiVersions)([])
|
|
867
|
+
], Collection.prototype, "reIndex", null);
|
|
868
|
+
__decorate([
|
|
869
|
+
(0, decorators_1.returnType)('Database')
|
|
870
|
+
], Collection.prototype, "getDB", null);
|
|
871
|
+
__decorate([
|
|
872
|
+
(0, decorators_1.returnType)('Mongo')
|
|
873
|
+
], Collection.prototype, "getMongo", null);
|
|
874
|
+
__decorate([
|
|
875
|
+
decorators_1.returnsPromise,
|
|
876
|
+
(0, decorators_1.apiVersions)([])
|
|
877
|
+
], Collection.prototype, "dataSize", null);
|
|
878
|
+
__decorate([
|
|
879
|
+
decorators_1.returnsPromise,
|
|
880
|
+
(0, decorators_1.apiVersions)([])
|
|
881
|
+
], Collection.prototype, "storageSize", null);
|
|
882
|
+
__decorate([
|
|
883
|
+
decorators_1.returnsPromise,
|
|
884
|
+
(0, decorators_1.apiVersions)([])
|
|
885
|
+
], Collection.prototype, "totalSize", null);
|
|
886
|
+
__decorate([
|
|
887
|
+
decorators_1.returnsPromise,
|
|
888
|
+
(0, decorators_1.apiVersions)([1])
|
|
889
|
+
], Collection.prototype, "drop", null);
|
|
890
|
+
__decorate([
|
|
891
|
+
decorators_1.returnsPromise,
|
|
892
|
+
(0, decorators_1.apiVersions)([1])
|
|
893
|
+
], Collection.prototype, "exists", null);
|
|
894
|
+
__decorate([
|
|
895
|
+
decorators_1.returnsPromise,
|
|
896
|
+
(0, decorators_1.apiVersions)([1])
|
|
897
|
+
], Collection.prototype, "runCommand", null);
|
|
898
|
+
__decorate([
|
|
899
|
+
(0, decorators_1.returnType)('Explainable'),
|
|
900
|
+
(0, decorators_1.apiVersions)([1])
|
|
901
|
+
], Collection.prototype, "explain", null);
|
|
902
|
+
__decorate([
|
|
903
|
+
decorators_1.returnsPromise,
|
|
904
|
+
(0, decorators_1.apiVersions)([])
|
|
905
|
+
], Collection.prototype, "stats", null);
|
|
906
|
+
__decorate([
|
|
907
|
+
decorators_1.returnsPromise,
|
|
908
|
+
(0, decorators_1.apiVersions)([])
|
|
909
|
+
], Collection.prototype, "latencyStats", null);
|
|
910
|
+
__decorate([
|
|
911
|
+
decorators_1.returnsPromise,
|
|
912
|
+
(0, decorators_1.returnType)('Bulk'),
|
|
913
|
+
(0, decorators_1.apiVersions)([1])
|
|
914
|
+
], Collection.prototype, "initializeOrderedBulkOp", null);
|
|
915
|
+
__decorate([
|
|
916
|
+
decorators_1.returnsPromise,
|
|
917
|
+
(0, decorators_1.returnType)('Bulk'),
|
|
918
|
+
(0, decorators_1.apiVersions)([1])
|
|
919
|
+
], Collection.prototype, "initializeUnorderedBulkOp", null);
|
|
920
|
+
__decorate([
|
|
921
|
+
(0, decorators_1.returnType)('PlanCache'),
|
|
922
|
+
(0, decorators_1.apiVersions)([])
|
|
923
|
+
], Collection.prototype, "getPlanCache", null);
|
|
924
|
+
__decorate([
|
|
925
|
+
decorators_1.returnsPromise,
|
|
926
|
+
decorators_1.deprecated,
|
|
927
|
+
(0, decorators_1.serverVersions)([enums_1.ServerVersions.earliest, '4.9.0']),
|
|
928
|
+
(0, decorators_1.apiVersions)([])
|
|
929
|
+
], Collection.prototype, "mapReduce", null);
|
|
930
|
+
__decorate([
|
|
931
|
+
decorators_1.returnsPromise,
|
|
932
|
+
(0, decorators_1.apiVersions)([])
|
|
933
|
+
], Collection.prototype, "validate", null);
|
|
934
|
+
__decorate([
|
|
935
|
+
decorators_1.returnsPromise,
|
|
936
|
+
(0, decorators_1.topologies)([enums_1.Topologies.Sharded]),
|
|
937
|
+
(0, decorators_1.apiVersions)([])
|
|
938
|
+
], Collection.prototype, "getShardVersion", null);
|
|
939
|
+
__decorate([
|
|
940
|
+
decorators_1.returnsPromise,
|
|
941
|
+
(0, decorators_1.topologies)([enums_1.Topologies.Sharded]),
|
|
942
|
+
(0, decorators_1.apiVersions)([])
|
|
943
|
+
], Collection.prototype, "getShardDistribution", null);
|
|
944
|
+
__decorate([
|
|
945
|
+
(0, decorators_1.serverVersions)(['3.1.0', enums_1.ServerVersions.latest]),
|
|
946
|
+
(0, decorators_1.topologies)([enums_1.Topologies.ReplSet, enums_1.Topologies.Sharded]),
|
|
947
|
+
(0, decorators_1.apiVersions)([1]),
|
|
948
|
+
decorators_1.returnsPromise
|
|
949
|
+
], Collection.prototype, "watch", null);
|
|
950
|
+
__decorate([
|
|
951
|
+
(0, decorators_1.serverVersions)(['4.4.0', enums_1.ServerVersions.latest]),
|
|
952
|
+
decorators_1.returnsPromise,
|
|
953
|
+
(0, decorators_1.apiVersions)([1])
|
|
954
|
+
], Collection.prototype, "hideIndex", null);
|
|
955
|
+
__decorate([
|
|
956
|
+
(0, decorators_1.serverVersions)(['4.4.0', enums_1.ServerVersions.latest]),
|
|
957
|
+
decorators_1.returnsPromise,
|
|
958
|
+
(0, decorators_1.apiVersions)([1])
|
|
959
|
+
], Collection.prototype, "unhideIndex", null);
|
|
960
|
+
Collection = __decorate([
|
|
961
|
+
decorators_1.shellApiClassDefault,
|
|
962
|
+
decorators_1.addSourceToResults
|
|
963
|
+
], Collection);
|
|
964
|
+
exports.default = Collection;
|
|
965
|
+
//# sourceMappingURL=collection.js.map
|