@documentdb-js/shell-api-types 0.8.0
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/LICENSE.md +21 -0
- package/README.md +105 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/methodRegistry.d.ts +28 -0
- package/dist/methodRegistry.d.ts.map +1 -0
- package/dist/methodRegistry.js +593 -0
- package/dist/methodRegistry.js.map +1 -0
- package/dist/methodRegistry.test.d.ts +2 -0
- package/dist/methodRegistry.test.d.ts.map +1 -0
- package/dist/methodRegistry.test.js +59 -0
- package/dist/methodRegistry.test.js.map +1 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +24 -0
- package/typeDefs/README.md +62 -0
- package/typeDefs/documentdb-shell-api.d.ts +899 -0
|
@@ -0,0 +1,899 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
// =============================================================================
|
|
7
|
+
// DocumentDB Shell API Type Definitions
|
|
8
|
+
//
|
|
9
|
+
// This file declares the shell API surface available in DocumentDB query playground
|
|
10
|
+
// (.documentdb.js) files. It is loaded by the TypeScript language service to
|
|
11
|
+
// provide autocompletion, hover docs, and signature help.
|
|
12
|
+
//
|
|
13
|
+
// The included methods were manually selected based on the Azure DocumentDB
|
|
14
|
+
// compatibility matrix. Azure DocumentDB uses the MongoDB wire protocol;
|
|
15
|
+
// client-side wrapper functions that rely on supported server commands are
|
|
16
|
+
// compatible. See README.md in this directory for the full methodology and
|
|
17
|
+
// reference links.
|
|
18
|
+
//
|
|
19
|
+
// IMPORTANT:
|
|
20
|
+
// - All JSDoc content is original writing.
|
|
21
|
+
// - Only methods mapping to supported DocumentDB server commands are included.
|
|
22
|
+
// - This file is the single source of truth for the query playground shell API.
|
|
23
|
+
// - When full MongoDB API support is added, a separate .d.ts can be swapped in.
|
|
24
|
+
// =============================================================================
|
|
25
|
+
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// BSON Types (used as return types)
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
/** A 12-byte unique identifier commonly used as `_id` values. */
|
|
31
|
+
declare class ObjectId {
|
|
32
|
+
constructor(hexString?: string);
|
|
33
|
+
/** Returns the 24-character hex representation. */
|
|
34
|
+
toString(): string;
|
|
35
|
+
/** Returns the ObjectId as a hex string. */
|
|
36
|
+
toHexString(): string;
|
|
37
|
+
/** Returns the Date the ObjectId was generated. */
|
|
38
|
+
getTimestamp(): Date;
|
|
39
|
+
/** Checks equality with another ObjectId. */
|
|
40
|
+
equals(other: ObjectId): boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** A 128-bit universally unique identifier (RFC 4122). */
|
|
44
|
+
declare class UUID {
|
|
45
|
+
constructor(hexString?: string);
|
|
46
|
+
toString(): string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A 32-bit signed integer. */
|
|
50
|
+
declare class Int32 {
|
|
51
|
+
constructor(value: number);
|
|
52
|
+
valueOf(): number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A 64-bit signed integer. */
|
|
56
|
+
declare class Long {
|
|
57
|
+
constructor(low: number, high?: number);
|
|
58
|
+
valueOf(): number;
|
|
59
|
+
toString(): string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A 128-bit decimal floating-point value (IEEE 754). */
|
|
63
|
+
declare class Decimal128 {
|
|
64
|
+
constructor(value: string);
|
|
65
|
+
toString(): string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** A 64-bit double-precision floating-point value. */
|
|
69
|
+
declare class Double {
|
|
70
|
+
constructor(value: number);
|
|
71
|
+
valueOf(): number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** An internal timestamp type used by the replication log. */
|
|
75
|
+
declare class Timestamp {
|
|
76
|
+
constructor(low: number, high: number);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** A binary data container. */
|
|
80
|
+
declare class Binary {
|
|
81
|
+
constructor(buffer: unknown, subType?: number);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A BSON regular expression. */
|
|
85
|
+
declare class BSONRegExp {
|
|
86
|
+
constructor(pattern: string, flags?: string);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Represents the smallest possible BSON value for comparisons. */
|
|
90
|
+
declare class MinKey {
|
|
91
|
+
constructor();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Represents the largest possible BSON value for comparisons. */
|
|
95
|
+
declare class MaxKey {
|
|
96
|
+
constructor();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** A reference to a document in another collection. */
|
|
100
|
+
declare class DBRef {
|
|
101
|
+
constructor(collection: string, id: ObjectId, db?: string);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** An executable JavaScript code value stored in BSON. */
|
|
105
|
+
declare class Code {
|
|
106
|
+
constructor(code: string, scope?: object);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
// BSON Constructor Functions (shell globals)
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Creates a new ObjectId.
|
|
115
|
+
* @param hexString Optional 24-character hex string. Generates a new ID if omitted.
|
|
116
|
+
* @example ObjectId("507f1f77bcf86cd799439011")
|
|
117
|
+
*/
|
|
118
|
+
declare function ObjectId(hexString?: string): ObjectId;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Creates a new UUID.
|
|
122
|
+
* @param hexString Optional UUID hex string. Generates a new UUID if omitted.
|
|
123
|
+
* @example UUID("123e4567-e89b-12d3-a456-426614174000")
|
|
124
|
+
*/
|
|
125
|
+
declare function UUID(hexString?: string): UUID;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Parses a date string into a Date object. Equivalent to `new Date(dateString)`.
|
|
129
|
+
* @param dateString An ISO 8601 date string. Uses current time if omitted.
|
|
130
|
+
* @example ISODate("2025-01-15T00:00:00Z")
|
|
131
|
+
*/
|
|
132
|
+
declare function ISODate(dateString?: string): Date;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Creates a 32-bit integer value.
|
|
136
|
+
* @param value The numeric value or string representation.
|
|
137
|
+
* @example NumberInt(42)
|
|
138
|
+
*/
|
|
139
|
+
declare function NumberInt(value?: number | string): Int32;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Creates a 64-bit integer value.
|
|
143
|
+
* @param value The numeric value or string representation.
|
|
144
|
+
* @example NumberLong(9007199254740993)
|
|
145
|
+
*/
|
|
146
|
+
declare function NumberLong(value?: number | string): Long;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Creates a 128-bit decimal value for high-precision arithmetic.
|
|
150
|
+
* @param value A string representation of the decimal number.
|
|
151
|
+
* @example NumberDecimal("0.1")
|
|
152
|
+
*/
|
|
153
|
+
declare function NumberDecimal(value?: string): Decimal128;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Creates a Timestamp value.
|
|
157
|
+
* @example Timestamp(0, 0)
|
|
158
|
+
*/
|
|
159
|
+
declare function Timestamp(low: number, high: number): Timestamp;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Creates a binary data value.
|
|
163
|
+
* @example BinData(0, "ZGF0YQ==")
|
|
164
|
+
*/
|
|
165
|
+
declare function BinData(subType: number, base64: string): Binary;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Creates a hex binary data value.
|
|
169
|
+
* @example HexData(0, "48656C6C6F")
|
|
170
|
+
*/
|
|
171
|
+
declare function HexData(subType: number, hex: string): Binary;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Creates a BSON regular expression.
|
|
175
|
+
* @example BSONRegExp("^test", "i")
|
|
176
|
+
*/
|
|
177
|
+
declare function BSONRegExp(pattern: string, flags?: string): BSONRegExp;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Creates a MD5 binary data value.
|
|
181
|
+
* @example MD5("abc123")
|
|
182
|
+
*/
|
|
183
|
+
declare function MD5(hex: string): Binary;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Creates a MinKey value for comparison operations.
|
|
187
|
+
* @example MinKey()
|
|
188
|
+
*/
|
|
189
|
+
declare function MinKey(): MinKey;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Creates a MaxKey value for comparison operations.
|
|
193
|
+
* @example MaxKey()
|
|
194
|
+
*/
|
|
195
|
+
declare function MaxKey(): MaxKey;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Creates a Double value.
|
|
199
|
+
* @example Double(3.14)
|
|
200
|
+
*/
|
|
201
|
+
declare function Double(value: number): Double;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Creates a Code value.
|
|
205
|
+
* @example Code("function() { return 1; }")
|
|
206
|
+
*/
|
|
207
|
+
declare function Code(code: string, scope?: object): Code;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Creates a DBRef (database reference) value.
|
|
211
|
+
* @example DBRef("collectionName", ObjectId("..."))
|
|
212
|
+
*/
|
|
213
|
+
declare function DBRef(collection: string, id: ObjectId, db?: string): DBRef;
|
|
214
|
+
|
|
215
|
+
// ---------------------------------------------------------------------------
|
|
216
|
+
// Shell Globals
|
|
217
|
+
// ---------------------------------------------------------------------------
|
|
218
|
+
|
|
219
|
+
/** The current database object. Use `db.<collection>` to access collections. */
|
|
220
|
+
declare const db: DocumentDBDatabase;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Switches the current database context.
|
|
224
|
+
* @param database The name of the database to switch to.
|
|
225
|
+
* @example use("myDatabase")
|
|
226
|
+
*/
|
|
227
|
+
declare function use(database: string): void;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Displays help information about available shell commands and methods.
|
|
231
|
+
* @example help()
|
|
232
|
+
*/
|
|
233
|
+
declare function help(): void;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Prints values to the output. Accepts any number of arguments.
|
|
237
|
+
* @example print("Count:", 42)
|
|
238
|
+
*/
|
|
239
|
+
declare function print(...args: unknown[]): void;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Prints a value in formatted JSON to the output.
|
|
243
|
+
* @example printjson({ name: "test" })
|
|
244
|
+
*/
|
|
245
|
+
declare function printjson(...args: unknown[]): void;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Pauses execution for the specified number of milliseconds.
|
|
249
|
+
* @param ms Duration in milliseconds.
|
|
250
|
+
* @example sleep(1000)
|
|
251
|
+
*/
|
|
252
|
+
declare function sleep(ms: number): void;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Returns the shell version string.
|
|
256
|
+
* @example version()
|
|
257
|
+
*/
|
|
258
|
+
declare function version(): string;
|
|
259
|
+
|
|
260
|
+
// ---------------------------------------------------------------------------
|
|
261
|
+
// EJSON utility
|
|
262
|
+
// ---------------------------------------------------------------------------
|
|
263
|
+
|
|
264
|
+
/** Utilities for working with Extended JSON (EJSON) serialization. */
|
|
265
|
+
declare const EJSON: {
|
|
266
|
+
/**
|
|
267
|
+
* Serializes a value to an Extended JSON string.
|
|
268
|
+
* @param value The value to serialize.
|
|
269
|
+
* @param options Formatting options.
|
|
270
|
+
* @example EJSON.stringify({ _id: ObjectId("...") })
|
|
271
|
+
*/
|
|
272
|
+
stringify(value: unknown, options?: { relaxed?: boolean; indent?: number | string }): string;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Parses an Extended JSON string back into a JavaScript value.
|
|
276
|
+
* @param text The EJSON string to parse.
|
|
277
|
+
* @example EJSON.parse('{"$oid": "507f1f77bcf86cd799439011"}')
|
|
278
|
+
*/
|
|
279
|
+
parse(text: string): unknown;
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
// ---------------------------------------------------------------------------
|
|
283
|
+
// Result Types
|
|
284
|
+
// ---------------------------------------------------------------------------
|
|
285
|
+
|
|
286
|
+
/** Result returned by an insertOne operation. */
|
|
287
|
+
interface InsertOneResult {
|
|
288
|
+
/** Whether the operation was acknowledged by the server. */
|
|
289
|
+
acknowledged: boolean;
|
|
290
|
+
/** The _id of the inserted document. */
|
|
291
|
+
insertedId: ObjectId;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Result returned by an insertMany operation. */
|
|
295
|
+
interface InsertManyResult {
|
|
296
|
+
/** Whether the operation was acknowledged by the server. */
|
|
297
|
+
acknowledged: boolean;
|
|
298
|
+
/** A map of the index to the _id of each inserted document. */
|
|
299
|
+
insertedIds: { [index: number]: ObjectId };
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** Result returned by an updateOne or updateMany operation. */
|
|
303
|
+
interface UpdateResult {
|
|
304
|
+
/** Whether the operation was acknowledged by the server. */
|
|
305
|
+
acknowledged: boolean;
|
|
306
|
+
/** The number of documents matched by the filter. */
|
|
307
|
+
matchedCount: number;
|
|
308
|
+
/** The number of documents modified. */
|
|
309
|
+
modifiedCount: number;
|
|
310
|
+
/** The number of documents upserted. */
|
|
311
|
+
upsertedCount: number;
|
|
312
|
+
/** The _id of the upserted document, if applicable. */
|
|
313
|
+
upsertedId: ObjectId | null;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** Result returned by a deleteOne or deleteMany operation. */
|
|
317
|
+
interface DeleteResult {
|
|
318
|
+
/** Whether the operation was acknowledged by the server. */
|
|
319
|
+
acknowledged: boolean;
|
|
320
|
+
/** The number of documents deleted. */
|
|
321
|
+
deletedCount: number;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** Result returned by a bulkWrite operation. */
|
|
325
|
+
interface BulkWriteResult {
|
|
326
|
+
/** Whether the operation was acknowledged by the server. */
|
|
327
|
+
acknowledged: boolean;
|
|
328
|
+
insertedCount: number;
|
|
329
|
+
matchedCount: number;
|
|
330
|
+
modifiedCount: number;
|
|
331
|
+
deletedCount: number;
|
|
332
|
+
upsertedCount: number;
|
|
333
|
+
insertedIds: { [index: number]: ObjectId };
|
|
334
|
+
upsertedIds: { [index: number]: ObjectId };
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// ---------------------------------------------------------------------------
|
|
338
|
+
// Database Interface
|
|
339
|
+
// ---------------------------------------------------------------------------
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Named methods on the database object. Separated from the index signature
|
|
343
|
+
* to avoid TS2411 errors (named properties must match the index type within
|
|
344
|
+
* a single interface). The intersection type `DocumentDBDatabase` below
|
|
345
|
+
* combines these methods with the dynamic collection access pattern.
|
|
346
|
+
*/
|
|
347
|
+
interface DocumentDBDatabaseMethods {
|
|
348
|
+
/**
|
|
349
|
+
* Returns a collection object for the specified name.
|
|
350
|
+
* @param name The collection name.
|
|
351
|
+
* @example db.getCollection("users")
|
|
352
|
+
*/
|
|
353
|
+
getCollection(name: string): DocumentDBCollection;
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Returns an array of collection names in the current database.
|
|
357
|
+
* @example db.getCollectionNames()
|
|
358
|
+
*/
|
|
359
|
+
getCollectionNames(): string[];
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Returns metadata about collections. Optionally filter by name or options.
|
|
363
|
+
* @param filter Optional filter document.
|
|
364
|
+
* @param nameOnly When true, returns only collection names.
|
|
365
|
+
* @example db.getCollectionInfos()
|
|
366
|
+
*/
|
|
367
|
+
getCollectionInfos(filter?: object, nameOnly?: boolean): object[];
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Creates a new collection in the current database.
|
|
371
|
+
* @param name The name of the collection to create.
|
|
372
|
+
* @param options Optional creation options (e.g. capped, size).
|
|
373
|
+
* @example db.createCollection("logs", { capped: true, size: 10000 })
|
|
374
|
+
*/
|
|
375
|
+
createCollection(name: string, options?: object): object;
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Drops the current database and all its collections.
|
|
379
|
+
* @example db.dropDatabase()
|
|
380
|
+
*/
|
|
381
|
+
dropDatabase(): object;
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Executes a database command directly.
|
|
385
|
+
* @param command The command document.
|
|
386
|
+
* @example db.runCommand({ ping: 1 })
|
|
387
|
+
*/
|
|
388
|
+
runCommand(command: object): object;
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Executes a command against the admin database.
|
|
392
|
+
* @param command The command document.
|
|
393
|
+
* @example db.adminCommand({ listDatabases: 1 })
|
|
394
|
+
*/
|
|
395
|
+
adminCommand(command: object): object;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Runs a database-level aggregation pipeline.
|
|
399
|
+
* @param pipeline An array of aggregation stage documents.
|
|
400
|
+
* @example db.aggregate([{ $listLocalSessions: {} }])
|
|
401
|
+
*/
|
|
402
|
+
aggregate(pipeline: object[]): DocumentDBAggregationCursor;
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Switches the database context to another database on the same cluster.
|
|
406
|
+
* @param database The name of the target database.
|
|
407
|
+
* @example db.getSiblingDB("admin")
|
|
408
|
+
*/
|
|
409
|
+
getSiblingDB(database: string): DocumentDBDatabase;
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Returns the name of the current database.
|
|
413
|
+
* @example db.getName()
|
|
414
|
+
*/
|
|
415
|
+
getName(): string;
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Returns storage statistics for the current database.
|
|
419
|
+
* @param options Optional statistics options or scale factor.
|
|
420
|
+
* @example db.stats()
|
|
421
|
+
*/
|
|
422
|
+
stats(options?: object): object;
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Returns the server version string.
|
|
426
|
+
* @example db.version()
|
|
427
|
+
*/
|
|
428
|
+
version(): string;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Creates a read-only view backed by an aggregation pipeline.
|
|
432
|
+
* @param name The name of the view to create.
|
|
433
|
+
* @param source The source collection name.
|
|
434
|
+
* @param pipeline The aggregation pipeline for the view.
|
|
435
|
+
* @example db.createView("activeUsers", "users", [{ $match: { active: true } }])
|
|
436
|
+
*/
|
|
437
|
+
createView(name: string, source: string, pipeline: object[]): object;
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Lists available database commands.
|
|
441
|
+
* @example db.listCommands()
|
|
442
|
+
*/
|
|
443
|
+
listCommands(): object;
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Creates a new database user with the specified name and roles.
|
|
447
|
+
* @param user The user document containing the username, password, and roles.
|
|
448
|
+
* @example db.createUser({ user: "readUser", pwd: "secret", roles: ["read"] })
|
|
449
|
+
*/
|
|
450
|
+
createUser(user: object): object;
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Removes a user from the current database.
|
|
454
|
+
* @param username The name of the user to remove.
|
|
455
|
+
* @example db.dropUser("readUser")
|
|
456
|
+
*/
|
|
457
|
+
dropUser(username: string): object;
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Terminates a running operation by its operation ID.
|
|
461
|
+
* @param opId The operation ID to terminate.
|
|
462
|
+
* @example db.killOp(12345)
|
|
463
|
+
*/
|
|
464
|
+
killOp(opId: number): object;
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Returns information about one or more users in the current database.
|
|
468
|
+
* @param filter Optional filter to select specific users.
|
|
469
|
+
* @example db.getUsers()
|
|
470
|
+
*/
|
|
471
|
+
getUsers(filter?: object): object;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Represents the current database. Access collections via `db.<name>` or
|
|
476
|
+
* `db.getCollection("<name>")`.
|
|
477
|
+
*
|
|
478
|
+
* Named methods are resolved first; unknown property names fall back to the
|
|
479
|
+
* index signature, returning a `DocumentDBCollection`.
|
|
480
|
+
*/
|
|
481
|
+
type DocumentDBDatabase = DocumentDBDatabaseMethods & {
|
|
482
|
+
/**
|
|
483
|
+
* Access a collection by name. Equivalent to `db.getCollection(name)`.
|
|
484
|
+
* @example db.users.find({})
|
|
485
|
+
* @example db["my-collection"].find({})
|
|
486
|
+
*/
|
|
487
|
+
[collectionName: string]: DocumentDBCollection;
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
// ---------------------------------------------------------------------------
|
|
491
|
+
// Collection Interface
|
|
492
|
+
// ---------------------------------------------------------------------------
|
|
493
|
+
|
|
494
|
+
/** Represents a collection in the current database. */
|
|
495
|
+
interface DocumentDBCollection {
|
|
496
|
+
/**
|
|
497
|
+
* Selects documents matching the filter. Returns a cursor for further
|
|
498
|
+
* refinement with `.limit()`, `.sort()`, `.skip()`, etc.
|
|
499
|
+
* @param filter Optional query filter document.
|
|
500
|
+
* @param projection Optional fields to include or exclude.
|
|
501
|
+
* @example db.users.find({ age: { $gt: 21 } })
|
|
502
|
+
* @example db.users.find({}, { name: 1, email: 1 })
|
|
503
|
+
*/
|
|
504
|
+
find(filter?: object, projection?: object): DocumentDBFindCursor;
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Returns the first document matching the filter, or null if none match.
|
|
508
|
+
* @param filter Optional query filter document.
|
|
509
|
+
* @param projection Optional fields to include or exclude.
|
|
510
|
+
* @example db.users.findOne({ _id: ObjectId("...") })
|
|
511
|
+
*/
|
|
512
|
+
findOne(filter?: object, projection?: object): object | null;
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Inserts a single document into the collection.
|
|
516
|
+
* @param document The document to insert.
|
|
517
|
+
* @param options Optional insert options.
|
|
518
|
+
* @example db.users.insertOne({ name: "Alice", age: 30 })
|
|
519
|
+
*/
|
|
520
|
+
insertOne(document: object, options?: object): InsertOneResult;
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Inserts multiple documents into the collection.
|
|
524
|
+
* @param documents An array of documents to insert.
|
|
525
|
+
* @param options Optional insert options (e.g. ordered).
|
|
526
|
+
* @example db.users.insertMany([{ name: "Bob" }, { name: "Carol" }])
|
|
527
|
+
*/
|
|
528
|
+
insertMany(documents: object[], options?: object): InsertManyResult;
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Updates the first document matching the filter.
|
|
532
|
+
* @param filter The selection criteria for the update.
|
|
533
|
+
* @param update The update operations to apply (e.g. `{ $set: { ... } }`).
|
|
534
|
+
* @param options Optional update options (e.g. upsert).
|
|
535
|
+
* @example db.users.updateOne({ _id: id }, { $set: { name: "Alice" } })
|
|
536
|
+
*/
|
|
537
|
+
updateOne(filter: object, update: object, options?: object): UpdateResult;
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Updates all documents matching the filter.
|
|
541
|
+
* @param filter The selection criteria for the update.
|
|
542
|
+
* @param update The update operations to apply.
|
|
543
|
+
* @param options Optional update options.
|
|
544
|
+
* @example db.users.updateMany({ active: false }, { $set: { archived: true } })
|
|
545
|
+
*/
|
|
546
|
+
updateMany(filter: object, update: object, options?: object): UpdateResult;
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Deletes the first document matching the filter.
|
|
550
|
+
* @param filter The selection criteria for deletion.
|
|
551
|
+
* @param options Optional delete options.
|
|
552
|
+
* @example db.users.deleteOne({ _id: id })
|
|
553
|
+
*/
|
|
554
|
+
deleteOne(filter: object, options?: object): DeleteResult;
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Deletes all documents matching the filter.
|
|
558
|
+
* @param filter The selection criteria for deletion.
|
|
559
|
+
* @param options Optional delete options.
|
|
560
|
+
* @example db.logs.deleteMany({ createdAt: { $lt: ISODate("2024-01-01") } })
|
|
561
|
+
*/
|
|
562
|
+
deleteMany(filter: object, options?: object): DeleteResult;
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Executes an aggregation pipeline on the collection.
|
|
566
|
+
* @param pipeline An array of aggregation stage documents.
|
|
567
|
+
* @param options Optional aggregation options.
|
|
568
|
+
* @example db.orders.aggregate([{ $match: { status: "shipped" } }, { $group: { _id: "$customer", total: { $sum: "$amount" } } }])
|
|
569
|
+
*/
|
|
570
|
+
aggregate(pipeline: object[], options?: object): DocumentDBAggregationCursor;
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Counts documents matching the filter using an aggregation pipeline.
|
|
574
|
+
* @param filter Optional query filter document.
|
|
575
|
+
* @param options Optional count options (e.g. limit, skip).
|
|
576
|
+
* @example db.users.countDocuments({ active: true })
|
|
577
|
+
*/
|
|
578
|
+
countDocuments(filter?: object, options?: object): number;
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Returns a fast approximate count of all documents in the collection.
|
|
582
|
+
* Uses collection metadata rather than scanning documents.
|
|
583
|
+
* @param options Optional estimation options.
|
|
584
|
+
* @example db.users.estimatedDocumentCount()
|
|
585
|
+
*/
|
|
586
|
+
estimatedDocumentCount(options?: object): number;
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Returns an array of distinct values for a given field.
|
|
590
|
+
* @param field The field path to get distinct values for.
|
|
591
|
+
* @param filter Optional query filter to limit which documents are considered.
|
|
592
|
+
* @param options Optional command options.
|
|
593
|
+
* @example db.users.distinct("country")
|
|
594
|
+
* @example db.users.distinct("city", { country: "US" })
|
|
595
|
+
*/
|
|
596
|
+
distinct(field: string, filter?: object, options?: object): unknown[];
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Creates an index on the specified field(s).
|
|
600
|
+
* @param keys A document specifying the index key pattern.
|
|
601
|
+
* @param options Optional index creation options (e.g. unique, name).
|
|
602
|
+
* @example db.users.createIndex({ email: 1 }, { unique: true })
|
|
603
|
+
*/
|
|
604
|
+
createIndex(keys: object, options?: object): string;
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Returns an array of documents describing the indexes on this collection.
|
|
608
|
+
* @example db.users.getIndexes()
|
|
609
|
+
*/
|
|
610
|
+
getIndexes(): object[];
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Drops an index by name or key specification.
|
|
614
|
+
* @param nameOrSpec The index name string or key specification document.
|
|
615
|
+
* @example db.users.dropIndex("email_1")
|
|
616
|
+
* @example db.users.dropIndex({ email: 1 })
|
|
617
|
+
*/
|
|
618
|
+
dropIndex(nameOrSpec: string | object): object;
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Drops the entire collection and all its documents and indexes.
|
|
622
|
+
* @example db.tempData.drop()
|
|
623
|
+
*/
|
|
624
|
+
drop(): boolean;
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Performs multiple write operations in a single batch.
|
|
628
|
+
* @param operations An array of write operation documents.
|
|
629
|
+
* @param options Optional bulk write options (e.g. ordered).
|
|
630
|
+
* @example db.users.bulkWrite([{ insertOne: { document: { name: "Dan" } } }])
|
|
631
|
+
*/
|
|
632
|
+
bulkWrite(operations: object[], options?: object): BulkWriteResult;
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Replaces a single document matching the filter with a new document.
|
|
636
|
+
* @param filter The selection criteria.
|
|
637
|
+
* @param replacement The replacement document (cannot contain update operators).
|
|
638
|
+
* @param options Optional replace options (e.g. upsert).
|
|
639
|
+
* @example db.users.replaceOne({ _id: id }, { name: "Alice", age: 31 })
|
|
640
|
+
*/
|
|
641
|
+
replaceOne(filter: object, replacement: object, options?: object): UpdateResult;
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Atomically finds a document matching the filter and updates it.
|
|
645
|
+
* Returns the document as it was before or after the update.
|
|
646
|
+
* @param filter The selection criteria.
|
|
647
|
+
* @param update The update operations to apply.
|
|
648
|
+
* @param options Optional options (e.g. returnDocument, upsert, projection).
|
|
649
|
+
* @example db.users.findOneAndUpdate({ _id: id }, { $inc: { visits: 1 } })
|
|
650
|
+
*/
|
|
651
|
+
findOneAndUpdate(filter: object, update: object, options?: object): object | null;
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Atomically finds a document matching the filter and deletes it.
|
|
655
|
+
* Returns the deleted document.
|
|
656
|
+
* @param filter The selection criteria.
|
|
657
|
+
* @param options Optional options (e.g. projection, sort).
|
|
658
|
+
* @example db.users.findOneAndDelete({ _id: id })
|
|
659
|
+
*/
|
|
660
|
+
findOneAndDelete(filter: object, options?: object): object | null;
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* Atomically finds a document matching the filter and replaces it.
|
|
664
|
+
* Returns the document as it was before or after the replacement.
|
|
665
|
+
* @param filter The selection criteria.
|
|
666
|
+
* @param replacement The replacement document.
|
|
667
|
+
* @param options Optional options (e.g. returnDocument, upsert).
|
|
668
|
+
* @example db.users.findOneAndReplace({ _id: id }, { name: "Alice", age: 31 })
|
|
669
|
+
*/
|
|
670
|
+
findOneAndReplace(filter: object, replacement: object, options?: object): object | null;
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Returns an explainable object that provides query plan information.
|
|
674
|
+
* @param verbosity Optional explain verbosity level.
|
|
675
|
+
* @example db.users.explain().find({ age: { $gt: 21 } })
|
|
676
|
+
*/
|
|
677
|
+
explain(verbosity?: string): DocumentDBCollection;
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Renames this collection to a new name.
|
|
681
|
+
* @param newName The new collection name.
|
|
682
|
+
* @param dropTarget If true, drops any existing collection with the new name.
|
|
683
|
+
* @example db.oldName.renameCollection("newName")
|
|
684
|
+
*/
|
|
685
|
+
renameCollection(newName: string, dropTarget?: boolean): object;
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Returns storage and index statistics for the collection.
|
|
689
|
+
* @param options Optional statistics options.
|
|
690
|
+
* @example db.users.stats()
|
|
691
|
+
*/
|
|
692
|
+
stats(options?: object): object;
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* Returns true if the collection is a capped collection.
|
|
696
|
+
* @example db.logs.isCapped()
|
|
697
|
+
*/
|
|
698
|
+
isCapped(): boolean;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
// ---------------------------------------------------------------------------
|
|
702
|
+
// Find Cursor Interface
|
|
703
|
+
// ---------------------------------------------------------------------------
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* A cursor returned by `find()`. Supports method chaining to refine the query
|
|
707
|
+
* before results are retrieved.
|
|
708
|
+
*/
|
|
709
|
+
interface DocumentDBFindCursor {
|
|
710
|
+
/**
|
|
711
|
+
* Limits the number of documents returned.
|
|
712
|
+
* @param n Maximum number of documents.
|
|
713
|
+
* @example db.users.find({}).limit(10)
|
|
714
|
+
*/
|
|
715
|
+
limit(n: number): DocumentDBFindCursor;
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Skips the first n documents in the result set.
|
|
719
|
+
* @param n Number of documents to skip.
|
|
720
|
+
* @example db.users.find({}).skip(20)
|
|
721
|
+
*/
|
|
722
|
+
skip(n: number): DocumentDBFindCursor;
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Specifies the sort order for the result set.
|
|
726
|
+
* @param spec A document with field names as keys and 1 (ascending) or -1 (descending) as values.
|
|
727
|
+
* @example db.users.find({}).sort({ age: -1 })
|
|
728
|
+
*/
|
|
729
|
+
sort(spec: object): DocumentDBFindCursor;
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* Retrieves all remaining documents as an array.
|
|
733
|
+
* @example const docs = db.users.find({}).toArray()
|
|
734
|
+
*/
|
|
735
|
+
toArray(): object[];
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* Iterates over each document, calling the provided function.
|
|
739
|
+
* @param fn A function to call for each document.
|
|
740
|
+
* @example db.users.find({}).forEach(doc => print(doc.name))
|
|
741
|
+
*/
|
|
742
|
+
forEach(fn: (doc: object) => void): void;
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Transforms each document using the provided function and returns a new cursor.
|
|
746
|
+
* @param fn A mapping function applied to each document.
|
|
747
|
+
* @example db.users.find({}).map(doc => doc.name)
|
|
748
|
+
*/
|
|
749
|
+
map(fn: (doc: object) => unknown): DocumentDBFindCursor;
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Returns the count of documents matching the query. Deprecated in favor of `countDocuments()`.
|
|
753
|
+
* @example db.users.find({ active: true }).count()
|
|
754
|
+
*/
|
|
755
|
+
count(): number;
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* Returns the query execution plan.
|
|
759
|
+
* @param verbosity Optional explain verbosity level.
|
|
760
|
+
* @example db.users.find({ age: { $gt: 21 } }).explain()
|
|
761
|
+
*/
|
|
762
|
+
explain(verbosity?: string): object;
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* Returns true if the cursor has more documents to return.
|
|
766
|
+
* @example while (cursor.hasNext()) { print(cursor.next()); }
|
|
767
|
+
*/
|
|
768
|
+
hasNext(): boolean;
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* Returns the next document from the cursor.
|
|
772
|
+
* @example const doc = cursor.next()
|
|
773
|
+
*/
|
|
774
|
+
next(): object | null;
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Sets the number of documents to fetch in each batch from the server.
|
|
778
|
+
* @param n The batch size.
|
|
779
|
+
* @example db.users.find({}).batchSize(50)
|
|
780
|
+
*/
|
|
781
|
+
batchSize(n: number): DocumentDBFindCursor;
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* Closes the cursor and releases server resources.
|
|
785
|
+
* @example cursor.close()
|
|
786
|
+
*/
|
|
787
|
+
close(): void;
|
|
788
|
+
|
|
789
|
+
/**
|
|
790
|
+
* Sets the collation options for string comparison.
|
|
791
|
+
* @param spec A collation specification document.
|
|
792
|
+
* @example db.users.find({}).collation({ locale: "en", strength: 2 })
|
|
793
|
+
*/
|
|
794
|
+
collation(spec: object): DocumentDBFindCursor;
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Instructs the query optimizer to use a specific index.
|
|
798
|
+
* @param spec An index name or key pattern document.
|
|
799
|
+
* @example db.users.find({}).hint({ email: 1 })
|
|
800
|
+
*/
|
|
801
|
+
hint(spec: object | string): DocumentDBFindCursor;
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* Attaches a comment to the query for profiling and logging.
|
|
805
|
+
* @param text The comment string.
|
|
806
|
+
* @example db.users.find({}).comment("admin lookup")
|
|
807
|
+
*/
|
|
808
|
+
comment(text: string): DocumentDBFindCursor;
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Sets the maximum execution time in milliseconds for the operation.
|
|
812
|
+
* @param ms Maximum time in milliseconds.
|
|
813
|
+
* @example db.users.find({}).maxTimeMS(5000)
|
|
814
|
+
*/
|
|
815
|
+
maxTimeMS(ms: number): DocumentDBFindCursor;
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* Sets the read concern level for the cursor.
|
|
819
|
+
* @param level The read concern level string.
|
|
820
|
+
* @example db.users.find({}).readConcern("majority")
|
|
821
|
+
*/
|
|
822
|
+
readConcern(level: string): DocumentDBFindCursor;
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* Sets the read preference for routing the query.
|
|
826
|
+
* @param mode The read preference mode.
|
|
827
|
+
* @param tagSet Optional tag set for targeting specific members.
|
|
828
|
+
* @example db.users.find({}).readPref("secondary")
|
|
829
|
+
*/
|
|
830
|
+
readPref(mode: string, tagSet?: object[]): DocumentDBFindCursor;
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Returns only the index key fields rather than the full document.
|
|
834
|
+
* @example db.users.find({}).returnKey()
|
|
835
|
+
*/
|
|
836
|
+
returnKey(): DocumentDBFindCursor;
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* Includes the internal storage engine record identifier with each document.
|
|
840
|
+
* @example db.users.find({}).showRecordId()
|
|
841
|
+
*/
|
|
842
|
+
showRecordId(): DocumentDBFindCursor;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
// ---------------------------------------------------------------------------
|
|
846
|
+
// Aggregation Cursor Interface
|
|
847
|
+
// ---------------------------------------------------------------------------
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* A cursor returned by `aggregate()`. Provides methods to consume
|
|
851
|
+
* the aggregation pipeline results.
|
|
852
|
+
*/
|
|
853
|
+
interface DocumentDBAggregationCursor {
|
|
854
|
+
/**
|
|
855
|
+
* Retrieves all remaining documents as an array.
|
|
856
|
+
* @example const results = db.orders.aggregate([...]).toArray()
|
|
857
|
+
*/
|
|
858
|
+
toArray(): object[];
|
|
859
|
+
|
|
860
|
+
/**
|
|
861
|
+
* Iterates over each document, calling the provided function.
|
|
862
|
+
* @param fn A function to call for each document.
|
|
863
|
+
*/
|
|
864
|
+
forEach(fn: (doc: object) => void): void;
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* Returns true if the cursor has more documents to return.
|
|
868
|
+
*/
|
|
869
|
+
hasNext(): boolean;
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* Returns the next document from the cursor.
|
|
873
|
+
*/
|
|
874
|
+
next(): object | null;
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* Sets the number of documents to fetch in each batch from the server.
|
|
878
|
+
* @param n The batch size.
|
|
879
|
+
*/
|
|
880
|
+
batchSize(n: number): DocumentDBAggregationCursor;
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* Closes the cursor and releases server resources.
|
|
884
|
+
*/
|
|
885
|
+
close(): void;
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Returns the execution plan for the aggregation pipeline.
|
|
889
|
+
* @param verbosity Optional explain verbosity level.
|
|
890
|
+
* @example db.orders.aggregate([...]).explain()
|
|
891
|
+
*/
|
|
892
|
+
explain(verbosity?: string): object;
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* Sets the maximum execution time in milliseconds for the operation.
|
|
896
|
+
* @param ms Maximum time in milliseconds.
|
|
897
|
+
*/
|
|
898
|
+
maxTimeMS(ms: number): DocumentDBAggregationCursor;
|
|
899
|
+
}
|