1 | // Type definitions for MongoDB 3.6
|
2 | // Project: https://github.com/mongodb/node-mongodb-native
|
3 | // https://github.com/mongodb/node-mongodb-native/tree/3.1
|
4 | // Definitions by: Federico Caselli <https://github.com/CaselIT>
|
5 | // Alan Marcell <https://github.com/alanmarcell>
|
6 | // Gaurav Lahoti <https://github.com/dante-101>
|
7 | // Mariano Cortesi <https://github.com/mcortesi>
|
8 | // Enrico Picci <https://github.com/EnricoPicci>
|
9 | // Alexander Christie <https://github.com/AJCStriker>
|
10 | // Julien Chaumond <https://github.com/julien-c>
|
11 | // Dan Aprahamian <https://github.com/daprahamian>
|
12 | // Denys Bushulyak <https://github.com/denys-bushulyak>
|
13 | // Bastien Arata <https://github.com/b4nst>
|
14 | // Wan Bachtiar <https://github.com/sindbach>
|
15 | // Geraldine Lemeur <https://github.com/geraldinelemeur>
|
16 | // Dominik Heigl <https://github.com/various89>
|
17 | // Angela-1 <https://github.com/angela-1>
|
18 | // Hector Ribes <https://github.com/hector7>
|
19 | // Florian Richter <https://github.com/floric>
|
20 | // Erik Christensen <https://github.com/erikc5000>
|
21 | // Nick Zahn <https://github.com/Manc>
|
22 | // Jarom Loveridge <https://github.com/jloveridge>
|
23 | // Luis Pais <https://github.com/ranguna>
|
24 | // Hossein Saniei <https://github.com/HosseinAgha>
|
25 | // Alberto Silva <https://github.com/albertossilva>
|
26 | // Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
27 | // Linus Unnebäck <https://github.com/LinusU>
|
28 | // Richard Bateman <https://github.com/taxilian>
|
29 | // Igor Strebezhev <https://github.com/xamgore>
|
30 | // Valentin Agachi <https://github.com/avaly>
|
31 | // HitkoDev <https://github.com/HitkoDev>
|
32 | // TJT <https://github.com/Celend>
|
33 | // Julien TASSIN <https://github.com/jtassin>
|
34 | // Anna Henningsen <https://github.com/addaleax>
|
35 | // Emmanuel Gautier <https://github.com/emmanuelgautier>
|
36 | // Wyatt Johnson <https://github.com/wyattjoh>
|
37 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
38 | // Minimum TypeScript Version: 3.2
|
39 |
|
40 | // Documentation: https://mongodb.github.io/node-mongodb-native/3.6/api/
|
41 |
|
42 | /// <reference types="node" />
|
43 | /// <reference lib="esnext.asynciterable" />
|
44 |
|
45 | import { Binary, Decimal128, Double, Int32, Long, ObjectId, Timestamp } from "bson";
|
46 | import { EventEmitter } from "events";
|
47 | import { Readable, Writable } from "stream";
|
48 | import { checkServerIdentity } from "tls";
|
49 |
|
50 | type FlattenIfArray<T> = T extends ReadonlyArray<infer R> ? R : T;
|
51 | export type WithoutProjection<T> = T & { fields?: undefined; projection?: undefined };
|
52 |
|
53 | export function connect(uri: string, options?: MongoClientOptions): Promise<MongoClient>;
|
54 | export function connect(uri: string, callback: MongoCallback<MongoClient>): void;
|
55 | export function connect(uri: string, options: MongoClientOptions, callback: MongoCallback<MongoClient>): void;
|
56 |
|
57 | export { Binary, DBRef, Decimal128, Double, Int32, Long, MaxKey, MinKey, ObjectID, ObjectId, Timestamp } from "bson";
|
58 |
|
59 | type NumericTypes = number | Decimal128 | Double | Int32 | Long;
|
60 |
|
61 | /**
|
62 | * Creates a new MongoClient instance
|
63 | *
|
64 | * @param uri The connection URI string
|
65 | * @param options Optional settings
|
66 | * @param callback The optional command result callback
|
67 | * @returns MongoClient instance
|
68 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoClient.html
|
69 | */
|
70 | export class MongoClient extends EventEmitter {
|
71 | constructor(uri: string, options?: MongoClientOptions);
|
72 | /**
|
73 | * Connect to MongoDB using a url as documented at
|
74 | * https://docs.mongodb.org/manual/reference/connection-string/
|
75 | *
|
76 | * @param uri The connection URI string
|
77 | * @param options Optional settings
|
78 | * @param callback The optional command result callback
|
79 | * @returns Promise if no callback is passed
|
80 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoClient.html#.connect
|
81 | */
|
82 | static connect(uri: string, callback: MongoCallback<MongoClient>): void;
|
83 | static connect(uri: string, options?: MongoClientOptions): Promise<MongoClient>;
|
84 | static connect(uri: string, options: MongoClientOptions, callback: MongoCallback<MongoClient>): void;
|
85 | /**
|
86 | * Connect to MongoDB using a url as documented at
|
87 | * https://docs.mongodb.org/manual/reference/connection-string/
|
88 | *
|
89 | * @param callback The optional command result callback
|
90 | * @returns Promise if no callback is passed
|
91 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoClient.html#connect
|
92 | */
|
93 | connect(): Promise<MongoClient>;
|
94 | connect(callback: MongoCallback<MongoClient>): void;
|
95 | /**
|
96 | * Close the db and its underlying connections
|
97 | *
|
98 | * @param force Optional force close, emitting no events
|
99 | * @param callback The optional result callback
|
100 | * @returns Promise if no callback is passed
|
101 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoClient.html#close
|
102 | */
|
103 | close(callback: MongoCallback<void>): void;
|
104 | close(force?: boolean): Promise<void>;
|
105 | close(force: boolean, callback: MongoCallback<void>): void;
|
106 | /**
|
107 | * Create a new Db instance sharing the current socket connections.
|
108 | * Be aware that the new db instances are related in a parent-child relationship to the original instance so that events are correctly emitted on child db instances.
|
109 | * Child db instances are cached so performing db('db1') twice will return the same instance.
|
110 | * You can control these behaviors with the options noListener and returnNonCachedInstance.
|
111 | *
|
112 | * @param dbName The name of the database we want to use. If not provided, use database name from connection string
|
113 | * @param options Optional settings
|
114 | * @returns The Db object
|
115 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoClient.html#db
|
116 | */
|
117 | db(dbName?: string, options?: MongoClientCommonOption): Db;
|
118 | /**
|
119 | * Check if MongoClient is connected
|
120 | *
|
121 | * @param options Optional settings
|
122 | * @returns Whether the MongoClient is connected or not
|
123 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoClient.html#isConnected
|
124 | */
|
125 | isConnected(options?: MongoClientCommonOption): boolean;
|
126 | /**
|
127 | * Starts a new session on the server
|
128 | *
|
129 | * @param options Optional settings for a driver session~
|
130 | * @returns Newly established session
|
131 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoClient.html#startSession
|
132 | */
|
133 | startSession(options?: SessionOptions): ClientSession;
|
134 | /**
|
135 | * Create a new Change Stream, watching for new changes (insertions, updates, replacements, deletions, and invalidations) in this cluster.
|
136 | * Will ignore all changes to system collections, as well as the local, admin, and config databases.
|
137 | *
|
138 | * @param pipeline An array of {//docs.mongodb.com/v3.6/reference/operator/aggregation-pipeline/ aggregation pipeline stages} through which to pass change stream documents.
https: |
139 | * This allows for filtering (using $match) and manipulating the change stream documents.
|
140 | * options Optional settings
|
141 | * ChangeStream instance
|
142 | * //mongodb.github.io/node-mongodb-native/3.6/api/MongoClient.html#watch
https: |
143 | */
|
144 | watch<TSchema extends object = { _id: ObjectId }>(
|
145 | pipeline?: object[],
|
146 | options?: ChangeStreamOptions & { session?: ClientSession },
|
147 | ): ChangeStream<TSchema>;
|
148 | /**
|
149 | * Runs a given operation with an implicitly created session. The lifetime of the session will be handled without the need for user interaction.
|
150 | * NOTE: presently the operation MUST return a Promise (either explicit or implicity as an async function)
|
151 | *
|
152 | * @param options Optional settings to be appled to implicitly created session
|
153 | * @param operation An operation to execute with an implicitly created session. The signature of this MUST be `(session) => {}`
|
154 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoClient.html#withSession
|
155 | */
|
156 | withSession(operation: (session: ClientSession) => Promise<any>): Promise<void>;
|
157 | withSession(options: SessionOptions, operation: (session: ClientSession) => Promise<any>): Promise<void>;
|
158 |
|
159 | readPreference: ReadPreference;
|
160 | writeConcern: WriteConcern;
|
161 | }
|
162 |
|
163 | export type ClientSessionId = unknown;
|
164 |
|
165 | /**
|
166 | * A class representing a client session on the server
|
167 | * WARNING: not meant to be instantiated directly.
|
168 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ClientSession.html
|
169 | */
|
170 | export interface ClientSession extends EventEmitter {
|
171 | /** The server id associated with this session */
|
172 | id: ClientSessionId;
|
173 |
|
174 | /**
|
175 | * Aborts the currently active transaction in this session.
|
176 | *
|
177 | * @param callback Optional callback for completion of this operation
|
178 | * @returns Promise if no callback is provided
|
179 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ClientSession.html#abortTransaction
|
180 | */
|
181 | abortTransaction(): Promise<void>;
|
182 | abortTransaction(callback?: MongoCallback<void>): void;
|
183 |
|
184 | /**
|
185 | * Advances the operationTime for a {@link ClientSession}.
|
186 | *
|
187 | * @param operationTime The `BSON.Timestamp` of the operation type it is desired to advance to
|
188 | */
|
189 | advanceOperationTime(operationTime: Timestamp): void;
|
190 |
|
191 | /**
|
192 | * Commits the currently active transaction in this session.
|
193 | *
|
194 | * @param callback Optional callback for completion of this operation
|
195 | * @returns Promise if no callback is provided
|
196 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ClientSession.html#commitTransaction
|
197 | */
|
198 | commitTransaction(): Promise<void>;
|
199 | commitTransaction(callback: MongoCallback<void>): void;
|
200 |
|
201 | /**
|
202 | * Ends this session on the server
|
203 | *
|
204 | * @param options Optional settings Currently reserved for future use
|
205 | * @param callback Optional callback for completion of this operation
|
206 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ClientSession.html#endSession
|
207 | */
|
208 | endSession(callback?: MongoCallback<void>): void;
|
209 | endSession(options: Object, callback: MongoCallback<void>): void;
|
210 | endSession(options?: Object): Promise<void>;
|
211 |
|
212 | /**
|
213 | * Used to determine if this session equals another
|
214 | *
|
215 | * @param session - a class representing a client session on the server
|
216 | * @returns `true` if the sessions are equal
|
217 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ClientSession.html#equals
|
218 | */
|
219 | equals(session: ClientSession): boolean;
|
220 |
|
221 | /**
|
222 | * Increment the transaction number on the internal `ServerSession`
|
223 | *
|
224 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ClientSession.html#incrementTransactionNumber
|
225 | */
|
226 | incrementTransactionNumber(): void;
|
227 |
|
228 | /**
|
229 | * @returns whether this session is currently in a transaction or not
|
230 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ClientSession.html#inTransaction
|
231 | */
|
232 | inTransaction(): boolean;
|
233 |
|
234 | /**
|
235 | * Starts a new transaction with the given options.
|
236 | *
|
237 | * @param options Options for the transaction
|
238 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ClientSession.html#startTransaction
|
239 | */
|
240 | startTransaction(options?: TransactionOptions): void;
|
241 |
|
242 | /**
|
243 | * Runs a provided lambda within a transaction, retrying either the commit operation
|
244 | * or entire transaction as needed (and when the error permits) to better ensure that
|
245 | * the transaction can complete successfully.
|
246 | *
|
247 | * IMPORTANT: This method requires the user to return a Promise, all lambdas that do not
|
248 | * return a Promise will result in undefined behavior.
|
249 | *
|
250 | * @param fn A user provided function to be run within a transaction
|
251 | * @param options Optional settings for the transaction
|
252 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ClientSession.html#withTransaction
|
253 | */
|
254 | withTransaction(fn: WithTransactionCallback, options?: TransactionOptions): Promise<any>;
|
255 | }
|
256 |
|
257 | /**
|
258 | * The MongoDB ReadConcern, which allows for control of the consistency and isolation properties
|
259 | * of the data read from replica sets and replica set shards.
|
260 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/global.html#ReadConcern
|
261 | */
|
262 | type ReadConcernLevel = "local" | "available" | "majority" | "linearizable" | "snapshot";
|
263 |
|
264 | /**
|
265 | * The MongoDB ReadConcern, which allows for control of the consistency and isolation properties
|
266 | * of the data read from replica sets and replica set shards.
|
267 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/global.html#ReadConcern
|
268 | */
|
269 | export interface ReadConcern {
|
270 | level: ReadConcernLevel;
|
271 | }
|
272 |
|
273 | /**
|
274 | * A MongoDB WriteConcern, which describes the level of acknowledgement
|
275 | * requested from MongoDB for write operations.
|
276 | *
|
277 | * @param w requests acknowledgement that the write operation has propagated to a specified number of mongod hosts
|
278 | * @param j requests acknowledgement from MongoDB that the write operation has been written to the journal
|
279 | * @param timeout a time limit, in milliseconds, for the write concern
|
280 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/global.html#WriteConcern
|
281 | */
|
282 | interface WriteConcern {
|
283 | /**
|
284 | * requests acknowledgement that the write operation has
|
285 | * propagated to a specified number of mongod hosts
|
286 | * @default 1
|
287 | */
|
288 | w?: number | "majority" | string;
|
289 | /**
|
290 | * requests acknowledgement from MongoDB that the write operation has
|
291 | * been written to the journal
|
292 | * @default false
|
293 | */
|
294 | j?: boolean;
|
295 | /**
|
296 | * a time limit, in milliseconds, for the write concern
|
297 | */
|
298 | wtimeout?: number;
|
299 | }
|
300 |
|
301 | /**
|
302 | * Options to pass when creating a Client Session
|
303 | *
|
304 | * @param causalConsistency Whether causal consistency should be enabled on this session
|
305 | * @param defaultTransactionOptions The default TransactionOptions to use for transactions started on this session.
|
306 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/global.html#SessionOptions
|
307 | */
|
308 | export interface SessionOptions {
|
309 | /**
|
310 | * Whether causal consistency should be enabled on this session
|
311 | * @default true
|
312 | */
|
313 | causalConsistency?: boolean;
|
314 | /**
|
315 | * The default TransactionOptions to use for transactions started on this session.
|
316 | */
|
317 | defaultTransactionOptions?: TransactionOptions;
|
318 | }
|
319 |
|
320 | /**
|
321 | * Configuration options for a transaction.
|
322 | *
|
323 | * @param readConcern A default read concern for commands in this transaction
|
324 | * @param writeConcern A default writeConcern for commands in this transaction
|
325 | * @param readPreference A default read preference for commands in this transaction
|
326 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/global.html#TransactionOptions
|
327 | */
|
328 | export interface TransactionOptions {
|
329 | readConcern?: ReadConcern;
|
330 | writeConcern?: WriteConcern;
|
331 | readPreference?: ReadPreferenceOrMode;
|
332 | }
|
333 |
|
334 | /**
|
335 | * @param noListener Do not make the db an event listener to the original connection.
|
336 | * @param returnNonCachedInstance Control if you want to return a cached instance or have a new one created
|
337 | */
|
338 | export interface MongoClientCommonOption {
|
339 | noListener?: boolean;
|
340 | returnNonCachedInstance?: boolean;
|
341 | }
|
342 |
|
343 | /**
|
344 | * The callback format for results
|
345 | *
|
346 | * @param error An error instance representing the error during the execution.
|
347 | * @param result The result object if the command was executed successfully.
|
348 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Admin.html#~resultCallback
|
349 | */
|
350 | export interface MongoCallback<T> {
|
351 | (error: MongoError, result: T): void;
|
352 | }
|
353 |
|
354 | /**
|
355 | * A user provided function to be run within a transaction
|
356 | *
|
357 | * @param session The parent session of the transaction running the operation. This should be passed into each operation within the lambda.
|
358 | * @returns Resulting Promise of operations run within this transaction
|
359 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/global.html#WithTransactionCallback
|
360 | */
|
361 | export type WithTransactionCallback = (session: ClientSession) => Promise<void>;
|
362 |
|
363 | /**
|
364 | * Creates a new MongoError
|
365 | *
|
366 | * @param message The error message
|
367 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoError.html
|
368 | */
|
369 | export class MongoError extends Error {
|
370 | constructor(message: string | Error | object);
|
371 | /**
|
372 | * Creates a new MongoError object
|
373 | *
|
374 | * @param options The options used to create the error
|
375 | * @returns A MongoError instance
|
376 | * @deprecated Use `new MongoError()` instead
|
377 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoError.html#.create
|
378 | */
|
379 | static create(options: string | Error | object): MongoError;
|
380 | /**
|
381 | * Checks the error to see if it has an error label
|
382 | *
|
383 | * @param options The options used to create the error
|
384 | * @returns `true` if the error has the provided error label
|
385 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoError.html#hasErrorLabel
|
386 | */
|
387 | hasErrorLabel(label: string): boolean;
|
388 | readonly errorLabels: string[];
|
389 | code?: number | string;
|
390 | /**
|
391 | * While not documented, the `errmsg` prop is AFAIK the only way to find out
|
392 | * which unique index caused a duplicate key error. When you have multiple
|
393 | * unique indexes on a collection, knowing which index caused a duplicate
|
394 | * key error enables you to send better (more precise) error messages to the
|
395 | * client/user (eg. "Email address must be unique" instead of "Both email
|
396 | * address and username must be unique") – which caters for a better (app)
|
397 | * user experience.
|
398 | *
|
399 | * Details:
|
400 | * {//github.com/Automattic/mongoose/issues/2129 How to get index name on duplicate document 11000 error?}
https: |
401 | * (issue for mongoose, but the same applies for the native mongodb driver).
|
402 | *
|
403 | * Note that in mongoose (the link above) the prop in question is called
|
404 | * 'message' while in mongodb it is called 'errmsg'. This can be seen in
|
405 | * multiple places in the source code, for example
|
406 | * {//github.com/mongodb/node-mongodb-native/blob/a12aa15ac3eaae3ad5c4166ea1423aec4560f155/test/functional/find_tests.js#L1111 here}.
https: |
407 | */
|
408 | errmsg?: string;
|
409 | name: string;
|
410 | }
|
411 |
|
412 | /**
|
413 | * An error indicating an issue with the network, including TCP errors and timeouts
|
414 | *
|
415 | * @param message The error message
|
416 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoNetworkError.html
|
417 | */
|
418 | export class MongoNetworkError extends MongoError {}
|
419 |
|
420 | /**
|
421 | * An error used when attempting to parse a value (like a connection string)
|
422 | *
|
423 | * @param message The error message
|
424 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoParseError.html
|
425 | */
|
426 | export class MongoParseError extends MongoError {}
|
427 |
|
428 | /**
|
429 | * An error signifying a client-side timeout event
|
430 | *
|
431 | * @param message The error message
|
432 | * @param reason The reason the timeout occured
|
433 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoTimeoutError.html
|
434 | */
|
435 | export class MongoTimeoutError extends MongoError {
|
436 | /**
|
437 | * An optional reason context for the timeout, generally an error
|
438 | * saved during flow of monitoring and selecting servers
|
439 | */
|
440 | reason?: string | object;
|
441 | }
|
442 |
|
443 | /**
|
444 | * An error signifying a client-side server selection error
|
445 | *
|
446 | * @param message The error message
|
447 | * @param reason The reason the timeout occured
|
448 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoServerSelectionError.html
|
449 | */
|
450 | export class MongoServerSelectionError extends MongoTimeoutError {}
|
451 |
|
452 | /**
|
453 | * An error thrown when the server reports a writeConcernError
|
454 | *
|
455 | * @param message The error message
|
456 | * @param reason The reason the timeout occured
|
457 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoWriteConcernError.html
|
458 | */
|
459 | export class MongoWriteConcernError extends MongoError {
|
460 | /**
|
461 | * The result document (provided if ok: 1)
|
462 | */
|
463 | result?: object;
|
464 | }
|
465 | /**
|
466 | * An error indicating an unsuccessful Bulk Write
|
467 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/BulkWriteError.html
|
468 | */
|
469 | export class BulkWriteError extends MongoError {}
|
470 | export { BulkWriteError as MongoBulkWriteError };
|
471 |
|
472 | /**
|
473 | * Optional settings for MongoClient.connect()
|
474 | *
|
475 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoClient.html#.connect
|
476 | */
|
477 | export interface MongoClientOptions
|
478 | extends DbCreateOptions,
|
479 | ServerOptions,
|
480 | MongosOptions,
|
481 | ReplSetOptions,
|
482 | SocketOptions,
|
483 | SSLOptions,
|
484 | TLSOptions,
|
485 | HighAvailabilityOptions,
|
486 | WriteConcern,
|
487 | UnifiedTopologyOptions {
|
488 | /**
|
489 | * The logging level (error/warn/info/debug)
|
490 | */
|
491 | loggerLevel?: string;
|
492 |
|
493 | /**
|
494 | * Custom logger object
|
495 | */
|
496 | logger?: object | log;
|
497 |
|
498 | /**
|
499 | * Validate MongoClient passed in options for correctness
|
500 | * @default false
|
501 | */
|
502 | validateOptions?: object | boolean;
|
503 |
|
504 | /**
|
505 | * The name of the application that created this MongoClient instance.
|
506 | */
|
507 | appname?: string;
|
508 |
|
509 | /**
|
510 | * Authentication credentials
|
511 | */
|
512 | auth?: {
|
513 | /**
|
514 | * The username for auth
|
515 | */
|
516 | user: string;
|
517 | /**
|
518 | * The password for auth
|
519 | */
|
520 | password: string;
|
521 | };
|
522 |
|
523 | /**
|
524 | * Determines whether or not to use the new url parser. Enables the new, spec-compliant
|
525 | * url parser shipped in the core driver. This url parser fixes a number of problems with
|
526 | * the original parser, and aims to outright replace that parser in the near future.
|
527 | * @default true
|
528 | */
|
529 | useNewUrlParser?: boolean;
|
530 |
|
531 | /**
|
532 | * Number of retries for a tailable cursor
|
533 | * @default 5
|
534 | */
|
535 | numberOfRetries?: number;
|
536 |
|
537 | /**
|
538 | * An authentication mechanism to use for connection authentication,
|
539 | * see the {@link https://docs.mongodb.com/v3.6/reference/connection-string/#urioption.authMechanism authMechanism}
|
540 | * reference for supported options.
|
541 | */
|
542 | authMechanism?:
|
543 | | "DEFAULT"
|
544 | | "GSSAPI"
|
545 | | "PLAIN"
|
546 | | "MONGODB-X509"
|
547 | | "MONGODB-CR"
|
548 | | "MONGODB-AWS"
|
549 | | "SCRAM-SHA-1"
|
550 | | "SCRAM-SHA-256"
|
551 | | string;
|
552 |
|
553 | /** Type of compression to use */
|
554 | compression?: {
|
555 | /** The selected compressors in preference order */
|
556 | compressors?: Array<"snappy" | "zlib">;
|
557 | };
|
558 |
|
559 | /**
|
560 | * Enable directConnection
|
561 | * @default false
|
562 | */
|
563 | directConnection?: boolean;
|
564 |
|
565 | /*
|
566 | * Optionally enable client side auto encryption.
|
567 | */
|
568 | autoEncryption?: AutoEncryptionOptions;
|
569 | }
|
570 |
|
571 | /**
|
572 | * Extra options related to the mongocryptd process.
|
573 | *
|
574 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AutoEncrypter.html#~AutoEncryptionExtraOptions
|
575 | */
|
576 | export interface AutoEncryptionExtraOptions {
|
577 | /**
|
578 | * A local process the driver communicates with to determine how to encrypt
|
579 | * values in a command. Defaults to "mongodb:///var/mongocryptd.sock" if
|
580 | * domain sockets are available or "mongodb://localhost:27020" otherwise.
|
581 | */
|
582 | mongocryptdURI?: string;
|
583 |
|
584 | /**
|
585 | * If true, autoEncryption will not attempt to spawn a mongocryptd before
|
586 | * connecting.
|
587 | */
|
588 | mongocryptdBypassSpawn?: boolean;
|
589 |
|
590 | /**
|
591 | * The path to the mongocryptd executable on the system.
|
592 | */
|
593 | mongocryptdSpawnPath?: string;
|
594 |
|
595 | /**
|
596 | * Command line arguments to use when auto-spawning a mongocryptd.
|
597 | */
|
598 | mongocryptdSpawnArgs?: string[];
|
599 | }
|
600 |
|
601 | /**
|
602 | * Configuration options that are used by specific KMS providers during key
|
603 | * generation, encryption, and decryption.
|
604 | *
|
605 | * @see http://mongodb.github.io/node-mongodb-native/3.6/api/global.html#KMSProviders
|
606 | */
|
607 | export interface KMSProviders {
|
608 | /**
|
609 | * Configuration options for using 'aws' as your KMS provider.
|
610 | */
|
611 | aws?: {
|
612 | /**
|
613 | * The access key used for the AWS KMS provider.
|
614 | */
|
615 | accessKeyId?: string;
|
616 |
|
617 | /**
|
618 | * The secret access key used for the AWS KMS provider.
|
619 | */
|
620 | secretAccessKey?: string;
|
621 | };
|
622 |
|
623 | /**
|
624 | * Configuration options for using `gcp` as your KMS provider.
|
625 | */
|
626 | gcp?: {
|
627 | /**
|
628 | * The service account email to authenticate.
|
629 | */
|
630 | email?: string;
|
631 |
|
632 | /**
|
633 | * A PKCS#8 encrypted key. This can either be a base64 string or a
|
634 | * binary representation.
|
635 | */
|
636 | privateKey?: string | Buffer;
|
637 |
|
638 | /**
|
639 | * If present, a host with optional port. E.g. "example.com" or
|
640 | * "example.com:443". Defaults to "oauth2.googleapis.com".
|
641 | */
|
642 | endpoint?: string;
|
643 | };
|
644 |
|
645 | /**
|
646 | * Configuration options for using 'local' as your KMS provider.
|
647 | */
|
648 | local?: {
|
649 | /**
|
650 | * The master key used to encrypt/decrypt data keys. A 96-byte long
|
651 | * Buffer.
|
652 | */
|
653 | key?: Buffer;
|
654 | };
|
655 | }
|
656 |
|
657 | /**
|
658 | * Configuration options for a automatic client encryption.
|
659 | *
|
660 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AutoEncrypter.html#~AutoEncryptionOptions
|
661 | */
|
662 | export interface AutoEncryptionOptions {
|
663 | /**
|
664 | * A MongoClient used to fetch keys from a key vault
|
665 | */
|
666 | keyVaultClient?: MongoClient;
|
667 |
|
668 | /**
|
669 | * The namespace where keys are stored in the key vault.
|
670 | */
|
671 | keyVaultNamespace?: string;
|
672 |
|
673 | /**
|
674 | * Configuration options that are used by specific KMS providers during key
|
675 | * generation, encryption, and decryption.
|
676 | */
|
677 | kmsProviders?: KMSProviders;
|
678 |
|
679 | /**
|
680 | * A map of namespaces to a local JSON schema for encryption.
|
681 | */
|
682 | schemaMap?: object;
|
683 |
|
684 | /**
|
685 | * Allows the user to bypass auto encryption, maintaining implicit
|
686 | * decryption.
|
687 | */
|
688 | bypassAutoEncryption?: boolean;
|
689 |
|
690 | /**
|
691 | * Extra options related to the mongocryptd process.
|
692 | */
|
693 | extraOptions?: AutoEncryptionExtraOptions;
|
694 | }
|
695 |
|
696 | export interface SSLOptions {
|
697 | /**
|
698 | * Passed directly through to tls.createSecureContext.
|
699 | *
|
700 | * @see https://nodejs.org/dist/latest/docs/api/tls.html#tls_tls_createsecurecontext_options
|
701 | */
|
702 | ciphers?: string;
|
703 | /**
|
704 | * Passed directly through to tls.createSecureContext.
|
705 | *
|
706 | * @see https://nodejs.org/dist/latest/docs/api/tls.html#tls_tls_createsecurecontext_options
|
707 | */
|
708 | ecdhCurve?: string;
|
709 | /**
|
710 | * Number of connections for each server instance; set to 5 as default for legacy reasons
|
711 | * @default 5
|
712 | */
|
713 | poolSize?: number;
|
714 | /**
|
715 | * If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections
|
716 | */
|
717 | minSize?: number;
|
718 | /**
|
719 | * Use ssl connection (needs to have a mongod server with ssl support)
|
720 | */
|
721 | ssl?: boolean;
|
722 | /**
|
723 | * Validate mongod server certificate against ca (mongod server >=2.4 with ssl support required)
|
724 | * @default true
|
725 | */
|
726 | sslValidate?: boolean;
|
727 | /**
|
728 | * Server identity checking during SSL
|
729 | * @default true
|
730 | */
|
731 | checkServerIdentity?: boolean | typeof checkServerIdentity;
|
732 | /**
|
733 | * Array of valid certificates either as Buffers or Strings
|
734 | */
|
735 | sslCA?: ReadonlyArray<Buffer | string>;
|
736 | /**
|
737 | * SSL Certificate revocation list binary buffer
|
738 | */
|
739 | sslCRL?: ReadonlyArray<Buffer | string>;
|
740 | /**
|
741 | * SSL Certificate binary buffer
|
742 | */
|
743 | sslCert?: Buffer | string;
|
744 | /**
|
745 | * SSL Key file binary buffer
|
746 | */
|
747 | sslKey?: Buffer | string;
|
748 | /**
|
749 | * SSL Certificate pass phrase
|
750 | */
|
751 | sslPass?: Buffer | string;
|
752 | /**
|
753 | * String containing the server name requested via TLS SNI.
|
754 | */
|
755 | servername?: string;
|
756 | }
|
757 |
|
758 | export interface TLSOptions {
|
759 | /**
|
760 | * Enable TLS connections
|
761 | * @default false
|
762 | */
|
763 | tls?: boolean;
|
764 | /**
|
765 | * Relax TLS constraints, disabling validation
|
766 | * @default false
|
767 | */
|
768 | tlsInsecure?: boolean;
|
769 | /**
|
770 | * Path to file with either a single or bundle of certificate authorities
|
771 | * to be considered trusted when making a TLS connection
|
772 | */
|
773 | tlsCAFile?: string;
|
774 | /**
|
775 | * Path to the client certificate file or the client private key file;
|
776 | * in the case that they both are needed, the files should be concatenated
|
777 | */
|
778 | tlsCertificateKeyFile?: string;
|
779 | /**
|
780 | * The password to decrypt the client private key to be used for TLS connections
|
781 | */
|
782 | tlsCertificateKeyFilePassword?: string;
|
783 | /**
|
784 | * Specifies whether or not the driver should error when the server’s TLS certificate is invalid
|
785 | */
|
786 | tlsAllowInvalidCertificates?: boolean;
|
787 | /**
|
788 | * Specifies whether or not the driver should error when there is a mismatch between the server’s hostname
|
789 | * and the hostname specified by the TLS certificate
|
790 | */
|
791 | tlsAllowInvalidHostnames?: boolean;
|
792 | }
|
793 |
|
794 | export interface HighAvailabilityOptions {
|
795 | /**
|
796 | * Turn on high availability monitoring
|
797 | * @default true
|
798 | */
|
799 | ha?: boolean;
|
800 | /**
|
801 | * The High availability period for replicaset inquiry
|
802 | * @default 10000
|
803 | */
|
804 | haInterval?: number;
|
805 | /**
|
806 | * @default false
|
807 | */
|
808 | domainsEnabled?: boolean;
|
809 |
|
810 | /**
|
811 | * The ReadPreference mode as listed
|
812 | * {@link https://mongodb.github.io/node-mongodb-native/3.6/api/MongoClient.html here}
|
813 | */
|
814 | readPreference?: ReadPreferenceOrMode;
|
815 | /**
|
816 | * An object representing read preference tags
|
817 | * @see https://docs.mongodb.com/v3.6/core/read-preference-tags/
|
818 | */
|
819 | readPreferenceTags?: ReadPreferenceTags;
|
820 | }
|
821 |
|
822 | export type ReadPreferenceTags = ReadonlyArray<Record<string, string>>;
|
823 | export type ReadPreferenceMode = "primary" | "primaryPreferred" | "secondary" | "secondaryPreferred" | "nearest";
|
824 | export type ReadPreferenceOrMode = ReadPreference | ReadPreferenceMode;
|
825 | export type ReadPreferenceOptions = {
|
826 | /** Server mode in which the same query is dispatched in parallel to multiple replica set members. */
|
827 | hedge?: {
|
828 | /** Explicitly enable or disable hedged reads. */
|
829 | enabled?: boolean;
|
830 | };
|
831 | /**
|
832 | * Max secondary read staleness in seconds, Minimum value is 90 seconds.
|
833 | */
|
834 | maxStalenessSeconds?: number;
|
835 | };
|
836 |
|
837 | /**
|
838 | * The **ReadPreference** class represents a MongoDB ReadPreference and is used to construct connections.
|
839 | * @see https://docs.mongodb.com/v3.6/core/read-preference/
|
840 | */
|
841 | export class ReadPreference {
|
842 | constructor(mode: ReadPreferenceMode, tags: object, options?: ReadPreferenceOptions);
|
843 | mode: ReadPreferenceMode;
|
844 | tags: ReadPreferenceTags;
|
845 | static PRIMARY: "primary";
|
846 | static PRIMARY_PREFERRED: "primaryPreferred";
|
847 | static SECONDARY: "secondary";
|
848 | static SECONDARY_PREFERRED: "secondaryPreferred";
|
849 | static NEAREST: "nearest";
|
850 | isValid(mode: ReadPreferenceMode | string): boolean;
|
851 | static isValid(mode: string): boolean;
|
852 | /**
|
853 | * Indicates that this readPreference needs the "slaveOk" bit when sent over the wire
|
854 | * @see https://docs.mongodb.com/v3.6/reference/mongodb-wire-protocol/#op-query
|
855 | */
|
856 | slaveOk(): boolean;
|
857 | /**
|
858 | * Are the two read preference equal
|
859 | * @param readPreference - the read preference with which to check equality
|
860 | * @returns `true` if the two ReadPreferences are equivalent
|
861 | */
|
862 | equals(readPreference: ReadPreference): boolean;
|
863 | }
|
864 |
|
865 | /**
|
866 | * Optional settings for creating a new Db instance
|
867 | *
|
868 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html
|
869 | */
|
870 | export interface DbCreateOptions extends CommonOptions {
|
871 | /**
|
872 | * If the database authentication is dependent on another databaseName.
|
873 | */
|
874 | authSource?: string;
|
875 | /**
|
876 | * Force server to assign `_id` fields instead of driver
|
877 | * @default false
|
878 | */
|
879 | forceServerObjectId?: boolean;
|
880 | /**
|
881 | * Use c++ bson parser
|
882 | * @default false
|
883 | */
|
884 | native_parser?: boolean;
|
885 | /**
|
886 | * Serialize functions on any object
|
887 | * @default false
|
888 | */
|
889 | serializeFunctions?: boolean;
|
890 | /**
|
891 | * Specify if the BSON serializer should ignore undefined fields
|
892 | * @default false
|
893 | */
|
894 | ignoreUndefined?: boolean;
|
895 | /**
|
896 | * Return document results as raw BSON buffers
|
897 | * @default false
|
898 | */
|
899 | raw?: boolean;
|
900 | /**
|
901 | * Promotes Long values to number if they fit inside the 53 bits resolution
|
902 | * @default true
|
903 | */
|
904 | promoteLongs?: boolean;
|
905 | /**
|
906 | * Promotes Binary BSON values to native Node Buffers
|
907 | * @default false
|
908 | */
|
909 | promoteBuffers?: boolean;
|
910 | /**
|
911 | * Promotes BSON values to native types where possible, set to false to only receive wrapper types
|
912 | * @default true
|
913 | */
|
914 | promoteValues?: boolean;
|
915 | /**
|
916 | * The preferred read preference. Use {@link ReadPreference} class.
|
917 | */
|
918 | readPreference?: ReadPreferenceOrMode;
|
919 | /**
|
920 | * A primary key factory object for generation of custom `_id` keys.
|
921 | */
|
922 | pkFactory?: object;
|
923 | /**
|
924 | * A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
|
925 | */
|
926 | promiseLibrary?: PromiseConstructor;
|
927 | /**
|
928 | * @see https://docs.mongodb.com/v3.6/reference/read-concern/#read-concern
|
929 | * @since MongoDB 3.2
|
930 | */
|
931 | readConcern?: ReadConcern | string;
|
932 | /**
|
933 | * Sets a cap on how many operations the driver will buffer up before giving up on getting a
|
934 | * working connection, default is -1 which is unlimited.
|
935 | */
|
936 | bufferMaxEntries?: number;
|
937 | }
|
938 |
|
939 | export interface UnifiedTopologyOptions {
|
940 | /**
|
941 | * Enables the new unified topology layer
|
942 | */
|
943 | useUnifiedTopology?: boolean;
|
944 |
|
945 | /**
|
946 | * **Only applies to the unified topology**
|
947 | * The size of the latency window for selecting among multiple suitable servers
|
948 | * @default 15
|
949 | */
|
950 | localThresholdMS?: number;
|
951 |
|
952 | /**
|
953 | * With `useUnifiedTopology`, the MongoDB driver will try to find a server to send any given operation to
|
954 | * and keep retrying for `serverSelectionTimeoutMS` milliseconds.
|
955 | * @default 30000
|
956 | */
|
957 | serverSelectionTimeoutMS?: number;
|
958 |
|
959 | /**
|
960 | * **Only applies to the unified topology**
|
961 | * The frequency with which topology updates are scheduled
|
962 | * @default 10000
|
963 | */
|
964 | heartbeatFrequencyMS?: number;
|
965 |
|
966 | /**
|
967 | * **Only applies to the unified topology**
|
968 | * The maximum number of connections that may be associated with a pool at a given time
|
969 | * This includes in use and available connections
|
970 | * @default 10
|
971 | */
|
972 | maxPoolSize?: number;
|
973 |
|
974 | /**
|
975 | * **Only applies to the unified topology**
|
976 | * The minimum number of connections that MUST exist at any moment in a single connection pool
|
977 | * @default 0
|
978 | */
|
979 | minPoolSize?: number;
|
980 |
|
981 | /**
|
982 | * **Only applies to the unified topology**
|
983 | * The maximum amount of time a connection should remain idle in the connection pool before being marked idle
|
984 | * @default Infinity
|
985 | */
|
986 | maxIdleTimeMS?: number;
|
987 |
|
988 | /**
|
989 | * **Only applies to the unified topology**
|
990 | * The maximum amount of time operation execution should wait for a connection to become available.
|
991 | * The default is 0 which means there is no limit.
|
992 | * @default 0
|
993 | */
|
994 | waitQueueTimeoutMS?: number;
|
995 | }
|
996 |
|
997 | /**
|
998 | * Optional socket options
|
999 | *
|
1000 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Server.html
|
1001 | */
|
1002 | export interface SocketOptions {
|
1003 | /**
|
1004 | * Reconnect on error
|
1005 | * @default true
|
1006 | */
|
1007 | autoReconnect?: boolean;
|
1008 | /**
|
1009 | * TCP Socket NoDelay option
|
1010 | * @default true
|
1011 | */
|
1012 | noDelay?: boolean;
|
1013 | /**
|
1014 | * TCP KeepAlive enabled on the socket
|
1015 | * @default true
|
1016 | */
|
1017 | keepAlive?: boolean;
|
1018 | /**
|
1019 | * TCP KeepAlive initial delay before sending first keep-alive packet when idle
|
1020 | * @default 30000
|
1021 | */
|
1022 | keepAliveInitialDelay?: number;
|
1023 | /**
|
1024 | * TCP Connection timeout setting
|
1025 | * @default 10000
|
1026 | */
|
1027 | connectTimeoutMS?: number;
|
1028 | /**
|
1029 | * Version of IP stack. Can be 4, 6 or null
|
1030 | * @default null
|
1031 | *
|
1032 | * If null, will attempt to connect with IPv6, and will fall back to IPv4 on failure
|
1033 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/MongoClient.html
|
1034 | */
|
1035 | family?: 4 | 6 | null;
|
1036 | /**
|
1037 | * TCP Socket timeout setting
|
1038 | * @default 360000
|
1039 | */
|
1040 | socketTimeoutMS?: number;
|
1041 | }
|
1042 |
|
1043 | /**
|
1044 | * Optional settings for creating a new Server instance
|
1045 | *
|
1046 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Server.html
|
1047 | */
|
1048 | export interface ServerOptions extends SSLOptions {
|
1049 | /**
|
1050 | * If you're connected to a single server or mongos proxy (as opposed to a replica set),
|
1051 | * the MongoDB driver will try to reconnect every reconnectInterval milliseconds for reconnectTries
|
1052 | * times, and give up afterward. When the driver gives up, the mongoose connection emits a
|
1053 | * reconnectFailed event.
|
1054 | * @default 30
|
1055 | */
|
1056 | reconnectTries?: number;
|
1057 | /**
|
1058 | * Will wait # milliseconds between retries
|
1059 | * @default 1000
|
1060 | */
|
1061 | reconnectInterval?: number;
|
1062 | /**
|
1063 | * @default true
|
1064 | */
|
1065 | monitoring?: boolean;
|
1066 |
|
1067 | /**
|
1068 | * Enable command monitoring for this client
|
1069 | * @default false
|
1070 | */
|
1071 | monitorCommands?: boolean;
|
1072 |
|
1073 | /**
|
1074 | * Socket Options
|
1075 | */
|
1076 | socketOptions?: SocketOptions;
|
1077 |
|
1078 | /**
|
1079 | * The High availability period for replicaset inquiry
|
1080 | * @default 10000
|
1081 | */
|
1082 | haInterval?: number;
|
1083 | /**
|
1084 | * @default false
|
1085 | */
|
1086 | domainsEnabled?: boolean;
|
1087 |
|
1088 | /**
|
1089 | * Specify a file sync write concern
|
1090 | * @default false
|
1091 | */
|
1092 | fsync?: boolean;
|
1093 | }
|
1094 |
|
1095 | /**
|
1096 | * Optional settings for creating a new Mongos instance
|
1097 | *
|
1098 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Mongos.html
|
1099 | */
|
1100 | export interface MongosOptions extends SSLOptions, HighAvailabilityOptions {
|
1101 | /**
|
1102 | * Cutoff latency point in MS for MongoS proxy selection
|
1103 | * @default 15
|
1104 | */
|
1105 | acceptableLatencyMS?: number;
|
1106 |
|
1107 | /**
|
1108 | * Socket Options
|
1109 | */
|
1110 | socketOptions?: SocketOptions;
|
1111 | }
|
1112 |
|
1113 | /**
|
1114 | * Optional settings for creating a new ReplSet instance
|
1115 | *
|
1116 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ReplSet.html
|
1117 | */
|
1118 | export interface ReplSetOptions extends SSLOptions, HighAvailabilityOptions {
|
1119 | /**
|
1120 | * The max staleness to secondary reads (values under 10 seconds cannot be guaranteed);
|
1121 | */
|
1122 | maxStalenessSeconds?: number;
|
1123 | /**
|
1124 | * The name of the replicaset to connect to.
|
1125 | */
|
1126 | replicaSet?: string;
|
1127 | /**
|
1128 | * Range of servers to pick when using NEAREST (lowest ping ms + the latency fence, ex: range of 1 to (1 + 15) ms)
|
1129 | * @default 15
|
1130 | */
|
1131 | secondaryAcceptableLatencyMS?: number;
|
1132 | /**
|
1133 | * If the driver should connect even if no primary is available
|
1134 | * @default false
|
1135 | */
|
1136 | connectWithNoPrimary?: boolean;
|
1137 | /**
|
1138 | * Optional socket options
|
1139 | *
|
1140 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Server.html
|
1141 | */
|
1142 | socketOptions?: SocketOptions;
|
1143 | }
|
1144 |
|
1145 | export type ProfilingLevel = "off" | "slow_only" | "all";
|
1146 |
|
1147 | /**
|
1148 | * Creates a new Db instance
|
1149 | *
|
1150 | * @param databaseName The name of the database this instance represents.
|
1151 | * @param topology The server topology for the database.
|
1152 | * @param options Optional settings
|
1153 | * @returns Db instance
|
1154 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html
|
1155 | */
|
1156 | export class Db extends EventEmitter {
|
1157 | constructor(databaseName: string, serverConfig: Server | ReplSet | Mongos, options?: DbCreateOptions);
|
1158 |
|
1159 | serverConfig: Server | ReplSet | Mongos;
|
1160 | bufferMaxEntries: number;
|
1161 | databaseName: string;
|
1162 | options: any;
|
1163 | native_parser: boolean;
|
1164 | slaveOk: boolean;
|
1165 | writeConcern: WriteConcern;
|
1166 |
|
1167 | /**
|
1168 | * Add a user to the database
|
1169 | *
|
1170 | * @param username The username
|
1171 | * @param password The password
|
1172 | * @param options Optional settings
|
1173 | * @param callback The command result callback
|
1174 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#addUser
|
1175 | */
|
1176 | addUser(username: string, password: string, callback: MongoCallback<any>): void;
|
1177 | addUser(username: string, password: string, options?: DbAddUserOptions): Promise<any>;
|
1178 | addUser(username: string, password: string, options: DbAddUserOptions, callback: MongoCallback<any>): void;
|
1179 | /**
|
1180 | * Return the Admin db instance
|
1181 | *
|
1182 | * @returns the new Admin db instance
|
1183 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#admin
|
1184 | */
|
1185 | admin(): Admin;
|
1186 | /**
|
1187 | * Fetch a specific collection (containing the actual collection information).
|
1188 | * If the application does not use strict mode you can use it without a callback in the following way: `const collection = db.collection('mycollection');`
|
1189 | *
|
1190 | * @param name The collection name you wish to access
|
1191 | * @param options Optional settings
|
1192 | * @param callback The collection result callback
|
1193 | * @returns Promise if no callback is passed
|
1194 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#collection
|
1195 | */
|
1196 | collection<TSchema = DefaultSchema>(
|
1197 | name: string,
|
1198 | callback?: MongoCallback<Collection<TSchema>>,
|
1199 | ): Collection<TSchema>;
|
1200 | collection<TSchema = DefaultSchema>(
|
1201 | name: string,
|
1202 | options: DbCollectionOptions,
|
1203 | callback?: MongoCallback<Collection<TSchema>>,
|
1204 | ): Collection<TSchema>;
|
1205 | /**
|
1206 | * Fetch all collections for the current db.
|
1207 | *
|
1208 | * @param options Optional settings
|
1209 | * @param callback The collection result callback
|
1210 | * @returns Promise if no callback is passed
|
1211 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#collections
|
1212 | */
|
1213 | collections(): Promise<Array<Collection<Default>>>;
|
1214 | collections(callback: MongoCallback<Array<Collection<Default>>>): void;
|
1215 | /**
|
1216 | * Execute a command
|
1217 | *
|
1218 | * @param command The command hash
|
1219 | * @param options Optional settings
|
1220 | * @param callback The command result callback
|
1221 | * @returns Promise if no callback is passed
|
1222 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#command
|
1223 | */
|
1224 | command(command: object, callback: MongoCallback<any>): void;
|
1225 | command(
|
1226 | command: object,
|
1227 | options?: { readPreference?: ReadPreferenceOrMode; session?: ClientSession },
|
1228 | ): Promise<any>;
|
1229 | command(
|
1230 | command: object,
|
1231 | options: { readPreference: ReadPreferenceOrMode; session?: ClientSession },
|
1232 | callback: MongoCallback<any>,
|
1233 | ): void;
|
1234 | /**
|
1235 | * Create a new collection on a server with the specified options. Use this to create capped collections.
|
1236 | * More information about command options available at {//docs.mongodb.com/v3.6/reference/command/create/}
https: |
1237 | *
|
1238 | * name The collection name we wish to access
|
1239 | * options Optional settings
|
1240 | * callback The results callback
|
1241 | * Promise if no callback is passed
|
1242 | * //mongodb.github.io/node-mongodb-native/3.6/api/Db.html#createCollection
https: |
1243 | */
|
1244 | createCollection<TSchema = DefaultSchema>(name: string, callback: MongoCallback<Collection<TSchema>>): void;
|
1245 | createCollection<TSchema = DefaultSchema>(
|
1246 | name: string,
|
1247 | options?: CollectionCreateOptions,
|
1248 | ): Promise<Collection<TSchema>>;
|
1249 | createCollection<TSchema = DefaultSchema>(
|
1250 | name: string,
|
1251 | options: CollectionCreateOptions,
|
1252 | callback: MongoCallback<Collection<TSchema>>,
|
1253 | ): void;
|
1254 | /**
|
1255 | * Creates an index on the db and collection.
|
1256 | *
|
1257 | * @param name Name of the collection to create the index on
|
1258 | * @param fieldOrSpec Defines the index
|
1259 | * @param options Optional settings
|
1260 | * @param callback The results callback
|
1261 | * @returns Promise if no callback is passed
|
1262 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#createIndex
|
1263 | */
|
1264 | createIndex(name: string, fieldOrSpec: string | object, callback: MongoCallback<any>): void;
|
1265 | createIndex(name: string, fieldOrSpec: string | object, options?: IndexOptions): Promise<any>;
|
1266 | createIndex(name: string, fieldOrSpec: string | object, options: IndexOptions, callback: MongoCallback<any>): void;
|
1267 | /**
|
1268 | * Drop a collection from the database, removing it permanently. New accesses will create a new collection.
|
1269 | *
|
1270 | * @param name Name of collection to drop
|
1271 | * @param options Optional settings
|
1272 | * @param callback The results callback
|
1273 | * @returns Promise if no callback is passed
|
1274 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#dropCollection
|
1275 | */
|
1276 | dropCollection(name: string): Promise<boolean>;
|
1277 | dropCollection(name: string, callback: MongoCallback<boolean>): void;
|
1278 | /**
|
1279 | * Drop a database, removing it permanently from the server.
|
1280 | *
|
1281 | * @param options Optional settings
|
1282 | * @param callback The results callback
|
1283 | * @returns Promise if no callback is passed
|
1284 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#dropDatabase
|
1285 | */
|
1286 | dropDatabase(): Promise<any>;
|
1287 | dropDatabase(callback: MongoCallback<any>): void;
|
1288 | /**
|
1289 | * Runs a command on the database as admin.
|
1290 | *
|
1291 | * @param command The command hash
|
1292 | * @param options Optional Settings
|
1293 | * @param callback The command result callback
|
1294 | * @returns Promise if no callback is passed
|
1295 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#executeDbAdminCommand
|
1296 | */
|
1297 | executeDbAdminCommand(command: object, callback: MongoCallback<any>): void;
|
1298 | executeDbAdminCommand(
|
1299 | command: object,
|
1300 | options?: { readPreference?: ReadPreferenceOrMode; session?: ClientSession },
|
1301 | ): Promise<any>;
|
1302 | executeDbAdminCommand(
|
1303 | command: object,
|
1304 | options: { readPreference?: ReadPreferenceOrMode; session?: ClientSession },
|
1305 | callback: MongoCallback<any>,
|
1306 | ): void;
|
1307 | /**
|
1308 | * Retrieves this collections index info.
|
1309 | *
|
1310 | * @param name The name of the collection
|
1311 | * @param options Optional settings
|
1312 | * @param callback The command result callback
|
1313 | * @returns Promise if no callback is passed
|
1314 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#indexInformation
|
1315 | */
|
1316 | indexInformation(name: string, callback: MongoCallback<any>): void;
|
1317 | indexInformation(name: string, options?: { full?: boolean; readPreference?: ReadPreferenceOrMode }): Promise<any>;
|
1318 | indexInformation(
|
1319 | name: string,
|
1320 | options: { full?: boolean; readPreference?: ReadPreferenceOrMode },
|
1321 | callback: MongoCallback<any>,
|
1322 | ): void;
|
1323 | /**
|
1324 | * Get the list of all collection information for the specified db.
|
1325 | *
|
1326 | * @param filter Query to filter collections by
|
1327 | * @param options Optional settings
|
1328 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#listCollections
|
1329 | */
|
1330 | listCollections(
|
1331 | filter?: object,
|
1332 | options?: {
|
1333 | nameOnly?: boolean;
|
1334 | batchSize?: number;
|
1335 | readPreference?: ReadPreferenceOrMode;
|
1336 | session?: ClientSession;
|
1337 | },
|
1338 | ): CommandCursor;
|
1339 | /**
|
1340 | * Retrieve the current profiling information for MongoDB
|
1341 | *
|
1342 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#profilingInfo
|
1343 | * @deprecated Query the system.profile collection directly.
|
1344 | */
|
1345 | profilingInfo(callback: MongoCallback<any>): void;
|
1346 | profilingInfo(options?: { session?: ClientSession }): Promise<void>;
|
1347 | profilingInfo(options: { session?: ClientSession }, callback: MongoCallback<void>): void;
|
1348 | /**
|
1349 | * Retrieve the current profiling Level for MongoDB
|
1350 | *
|
1351 | * @param options Optional settings
|
1352 | * @param callback The command result callback
|
1353 | * @returns Promise if no callback is passed
|
1354 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#profilingLevel
|
1355 | */
|
1356 | profilingLevel(callback: MongoCallback<ProfilingLevel>): void;
|
1357 | profilingLevel(options?: { session?: ClientSession }): Promise<ProfilingLevel>;
|
1358 | profilingLevel(options: { session?: ClientSession }, callback: MongoCallback<ProfilingLevel>): void;
|
1359 | /**
|
1360 | * Remove a user from a database
|
1361 | *
|
1362 | * @param username The username
|
1363 | * @param options Optional settings
|
1364 | * @param callback The command result callback
|
1365 | * @returns Promise if no callback is passed
|
1366 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#removeUser
|
1367 | */
|
1368 | removeUser(username: string, callback: MongoCallback<any>): void;
|
1369 | removeUser(username: string, options?: CommonOptions): Promise<any>;
|
1370 | removeUser(username: string, options: CommonOptions, callback: MongoCallback<any>): void;
|
1371 | /**
|
1372 | * Rename a collection
|
1373 | *
|
1374 | * @param fromCollection Name of current collection to rename
|
1375 | * @param toCollection New name of of the collection
|
1376 | * @param options Optional settings
|
1377 | * @param callback The command result callback
|
1378 | * @returns Promise if no callback is passed
|
1379 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#renameCollection
|
1380 | */
|
1381 | renameCollection<TSchema = DefaultSchema>(
|
1382 | fromCollection: string,
|
1383 | toCollection: string,
|
1384 | callback: MongoCallback<Collection<TSchema>>,
|
1385 | ): void;
|
1386 | renameCollection<TSchema = DefaultSchema>(
|
1387 | fromCollection: string,
|
1388 | toCollection: string,
|
1389 | options?: { dropTarget?: boolean },
|
1390 | ): Promise<Collection<TSchema>>;
|
1391 | renameCollection<TSchema = DefaultSchema>(
|
1392 | fromCollection: string,
|
1393 | toCollection: string,
|
1394 | options: { dropTarget?: boolean },
|
1395 | callback: MongoCallback<Collection<TSchema>>,
|
1396 | ): void;
|
1397 | /**
|
1398 | * Set the current profiling level of MongoDB
|
1399 | *
|
1400 | * @param level The new profiling level (off, slow_only, all)
|
1401 | * @param options Optional settings
|
1402 | * @param callback The command result callback
|
1403 | * @returns Promise if no callback is passed
|
1404 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#setProfilingLevel
|
1405 | */
|
1406 | setProfilingLevel(level: ProfilingLevel, callback: MongoCallback<ProfilingLevel>): void;
|
1407 | setProfilingLevel(level: ProfilingLevel, options?: { session?: ClientSession }): Promise<ProfilingLevel>;
|
1408 | setProfilingLevel(
|
1409 | level: ProfilingLevel,
|
1410 | options: { session?: ClientSession },
|
1411 | callback: MongoCallback<ProfilingLevel>,
|
1412 | ): void;
|
1413 | /**
|
1414 | * Get all the db statistics.
|
1415 | *
|
1416 | * @param options Optional settings
|
1417 | * @param callback The command result callback
|
1418 | * @returns Promise if no callback is passed
|
1419 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#stats
|
1420 | */
|
1421 | stats(callback: MongoCallback<any>): void;
|
1422 | stats(options?: { scale?: number }): Promise<any>;
|
1423 | stats(options: { scale?: number }, callback: MongoCallback<any>): void;
|
1424 | /**
|
1425 | * Unref all sockets
|
1426 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#unref
|
1427 | */
|
1428 | unref(): void;
|
1429 | /**
|
1430 | * Create a new Change Stream, watching for new changes (insertions, updates, replacements, deletions, and invalidations) in this database.
|
1431 | * Will ignore all changes to system collections.
|
1432 | *
|
1433 | * @param pipeline An array of {@link https://docs.mongodb.com/v3.6/reference/operator/aggregation-pipeline/ aggregation pipeline stages} through which to pass change stream documents.
|
1434 | * This allows for filtering (using $match) and manipulating the change stream documents.
|
1435 | * @param options Optional settings
|
1436 | * @returns ChangeStream instance
|
1437 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#watch
|
1438 | */
|
1439 | watch<TSchema extends object = { _id: ObjectId }>(
|
1440 | pipeline?: object[],
|
1441 | options?: ChangeStreamOptions & { session?: ClientSession },
|
1442 | ): ChangeStream<TSchema>;
|
1443 | }
|
1444 |
|
1445 | export interface CommonOptions extends WriteConcern {
|
1446 | session?: ClientSession;
|
1447 | }
|
1448 |
|
1449 | /**
|
1450 | * Creates a new Server instance
|
1451 | *
|
1452 | * @param host The host for the server, can be either an IP4, IP6 or domain socket style host.
|
1453 | * @param port The server port if IP4.
|
1454 | * @param options Optional settings
|
1455 | * @returns Server instance
|
1456 | * @deprecated
|
1457 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Server.html
|
1458 | */
|
1459 | export class Server extends EventEmitter {
|
1460 | constructor(host: string, port: number, options?: ServerOptions);
|
1461 |
|
1462 | connections(): any[];
|
1463 | }
|
1464 |
|
1465 | /**
|
1466 | * Creates a new ReplSet instance
|
1467 | *
|
1468 | * @param servers A seedlist of servers participating in the replicaset.
|
1469 | * @param options Optional settings
|
1470 | * @deprecated
|
1471 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ReplSet.html
|
1472 | */
|
1473 | export class ReplSet extends EventEmitter {
|
1474 | constructor(servers: Server[], options?: ReplSetOptions);
|
1475 |
|
1476 | connections(): any[];
|
1477 | }
|
1478 |
|
1479 | /**
|
1480 | * Creates a new Mongos instance
|
1481 | *
|
1482 | * @param servers A seedlist of servers participating in the replicaset.
|
1483 | * @param options Optional settings
|
1484 | * @deprecated
|
1485 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Mongos.html
|
1486 | */
|
1487 | export class Mongos extends EventEmitter {
|
1488 | constructor(servers: Server[], options?: MongosOptions);
|
1489 |
|
1490 | connections(): any[];
|
1491 | }
|
1492 |
|
1493 | /**
|
1494 | * Optional settings for adding a user to the database
|
1495 | *
|
1496 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#addUser
|
1497 | */
|
1498 | export interface DbAddUserOptions extends CommonOptions {
|
1499 | customData?: object;
|
1500 | roles?: object[];
|
1501 | }
|
1502 |
|
1503 | /**
|
1504 | * Options for creating a new collection on a server
|
1505 | *
|
1506 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#createCollection
|
1507 | */
|
1508 | export interface CollectionCreateOptions extends CommonOptions {
|
1509 | raw?: boolean;
|
1510 | pkFactory?: object;
|
1511 | readPreference?: ReadPreferenceOrMode;
|
1512 | serializeFunctions?: boolean;
|
1513 | /**
|
1514 | * @deprecated
|
1515 | * @see https://jira.mongodb.org/browse/NODE-2746
|
1516 | */
|
1517 | strict?: boolean;
|
1518 | capped?: boolean;
|
1519 | /**
|
1520 | * @deprecated
|
1521 | */
|
1522 | autoIndexId?: boolean;
|
1523 | size?: number;
|
1524 | max?: number;
|
1525 | flags?: number;
|
1526 | storageEngine?: object;
|
1527 | validator?: object;
|
1528 | validationLevel?: "off" | "strict" | "moderate";
|
1529 | validationAction?: "error" | "warn";
|
1530 | indexOptionDefaults?: object;
|
1531 | viewOn?: string;
|
1532 | pipeline?: any[];
|
1533 | collation?: CollationDocument;
|
1534 | }
|
1535 |
|
1536 | /**
|
1537 | * Options for fetching a specific collection.
|
1538 | *
|
1539 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#collection
|
1540 | */
|
1541 | export interface DbCollectionOptions extends CommonOptions {
|
1542 | raw?: boolean;
|
1543 | pkFactory?: object;
|
1544 | readPreference?: ReadPreferenceOrMode;
|
1545 | serializeFunctions?: boolean;
|
1546 | strict?: boolean;
|
1547 | readConcern?: ReadConcern;
|
1548 | }
|
1549 |
|
1550 | /**
|
1551 | * Options for creating an index on the db and collection.
|
1552 | *
|
1553 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html#createIndex
|
1554 | */
|
1555 | export interface IndexOptions extends CommonOptions {
|
1556 | /**
|
1557 | * Creates an unique index.
|
1558 | */
|
1559 | unique?: boolean;
|
1560 | /**
|
1561 | * Creates a sparse index.
|
1562 | */
|
1563 | sparse?: boolean;
|
1564 | /**
|
1565 | * Creates the index in the background, yielding whenever possible.
|
1566 | */
|
1567 | background?: boolean;
|
1568 | /**
|
1569 | * A unique index cannot be created on a key that has pre-existing duplicate values.
|
1570 | *
|
1571 | * If you would like to create the index anyway, keeping the first document the database indexes and
|
1572 | * deleting all subsequent documents that have duplicate value
|
1573 | */
|
1574 | dropDups?: boolean;
|
1575 | /**
|
1576 | * For geo spatial indexes set the lower bound for the co-ordinates.
|
1577 | */
|
1578 | min?: number;
|
1579 | /**
|
1580 | * For geo spatial indexes set the high bound for the co-ordinates.
|
1581 | */
|
1582 | max?: number;
|
1583 | /**
|
1584 | * Specify the format version of the indexes.
|
1585 | */
|
1586 | v?: number;
|
1587 | /**
|
1588 | * Allows you to expire data on indexes applied to a data (MongoDB 2.2 or higher)
|
1589 | */
|
1590 | expireAfterSeconds?: number;
|
1591 | /**
|
1592 | * Override the auto generated index name (useful if the resulting name is larger than 128 bytes)
|
1593 | */
|
1594 | name?: string;
|
1595 | /**
|
1596 | * Creates a partial index based on the given filter object (MongoDB 3.2 or higher)
|
1597 | */
|
1598 | partialFilterExpression?: any;
|
1599 | collation?: CollationDocument;
|
1600 | default_language?: string;
|
1601 | }
|
1602 |
|
1603 | /**
|
1604 | * Create a new Admin instance (INTERNAL TYPE, do not instantiate directly)
|
1605 | *
|
1606 | * @returns Collection instance
|
1607 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Admin.html
|
1608 | */
|
1609 | export interface Admin {
|
1610 | /**
|
1611 | * Add a user to the database.
|
1612 | *
|
1613 | * @param username The username
|
1614 | * @param password The password
|
1615 | * @param options Optional settings
|
1616 | * @param callback The command result callback
|
1617 | * @returns Promise if no callback is passed
|
1618 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Admin.html#addUser
|
1619 | */
|
1620 | addUser(username: string, password: string, callback: MongoCallback<any>): void;
|
1621 | addUser(username: string, password: string, options?: AddUserOptions): Promise<any>;
|
1622 | addUser(username: string, password: string, options: AddUserOptions, callback: MongoCallback<any>): void;
|
1623 | /**
|
1624 | * Retrieve the server information for the current instance of the db client
|
1625 | *
|
1626 | * @param options Optional settings
|
1627 | * @param callback The command result callback
|
1628 | * @returns Promise if no callback is passed
|
1629 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Admin.html#buildInfo
|
1630 | */
|
1631 | buildInfo(options?: { session?: ClientSession }): Promise<any>;
|
1632 | buildInfo(options: { session?: ClientSession }, callback: MongoCallback<any>): void;
|
1633 | buildInfo(callback: MongoCallback<any>): void;
|
1634 | /**
|
1635 | * Execute a command
|
1636 | *
|
1637 | * @param command The command hash
|
1638 | * @param options Optional settings
|
1639 | * @param callback The command result callback
|
1640 | * @returns Promise if no callback is passed
|
1641 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Admin.html#command
|
1642 | */
|
1643 | command(command: object, callback: MongoCallback<any>): void;
|
1644 | command(command: object, options?: { readPreference?: ReadPreferenceOrMode; maxTimeMS?: number }): Promise<any>;
|
1645 | command(
|
1646 | command: object,
|
1647 | options: { readPreference?: ReadPreferenceOrMode; maxTimeMS?: number },
|
1648 | callback: MongoCallback<any>,
|
1649 | ): void;
|
1650 | /**
|
1651 | * List the available databases
|
1652 | *
|
1653 | * @param options Optional settings
|
1654 | * @param callback The command result callback
|
1655 | * @returns Promise if no callback is passed
|
1656 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Admin.html#listDatabases
|
1657 | */
|
1658 | listDatabases(options?: { nameOnly?: boolean; session?: ClientSession }): Promise<any>;
|
1659 | listDatabases(options: { nameOnly?: boolean; session?: ClientSession }, callback: MongoCallback<any>): void;
|
1660 | listDatabases(callback: MongoCallback<any>): void;
|
1661 | /**
|
1662 | * Ping the MongoDB server and retrieve results
|
1663 | *
|
1664 | * @param options Optional settings
|
1665 | * @param callback The command result callback
|
1666 | * @returns Promise if no callback is passed
|
1667 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Admin.html#ping
|
1668 | */
|
1669 | ping(options?: { session?: ClientSession }): Promise<any>;
|
1670 | ping(options: { session?: ClientSession }, callback: MongoCallback<any>): void;
|
1671 | ping(callback: MongoCallback<any>): void;
|
1672 | /**
|
1673 | * Remove a user from a database
|
1674 | *
|
1675 | * @param username The username
|
1676 | * @param options Optional settings
|
1677 | * @param callback The command result callback
|
1678 | * @returns Promise if no callback is passed
|
1679 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Admin.html#removeUser
|
1680 | */
|
1681 | removeUser(username: string, callback: MongoCallback<any>): void;
|
1682 | removeUser(username: string, options?: FSyncOptions): Promise<any>;
|
1683 | removeUser(username: string, options: FSyncOptions, callback: MongoCallback<any>): void;
|
1684 | /**
|
1685 | * Get ReplicaSet status
|
1686 | *
|
1687 | * @param options Optional settings
|
1688 | * @param callback The command result callback
|
1689 | * @returns Promise if no callback is passed
|
1690 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Admin.html#replSetGetStatus
|
1691 | */
|
1692 | replSetGetStatus(options?: { session?: ClientSession }): Promise<any>;
|
1693 | replSetGetStatus(options: { session?: ClientSession }, callback: MongoCallback<any>): void;
|
1694 | replSetGetStatus(callback: MongoCallback<any>): void;
|
1695 | /**
|
1696 | * Retrieve the server information for the current instance of the db client
|
1697 | *
|
1698 | * @param options Optional settings
|
1699 | * @param callback The command result callback
|
1700 | * @returns Promise if no callback is passed
|
1701 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Admin.html#serverInfo
|
1702 | */
|
1703 | serverInfo(): Promise<any>;
|
1704 | serverInfo(callback: MongoCallback<any>): void;
|
1705 | /**
|
1706 | * Retrieve this db's server status.
|
1707 | *
|
1708 | * @param options Optional settings
|
1709 | * @param callback The command result callback
|
1710 | * @returns Promise if no callback is passed
|
1711 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Admin.html#serverStatus
|
1712 | */
|
1713 | serverStatus(options?: { session?: ClientSession }): Promise<any>;
|
1714 | serverStatus(options: { session?: ClientSession }, callback: MongoCallback<any>): void;
|
1715 | serverStatus(callback: MongoCallback<any>): void;
|
1716 | /**
|
1717 | * Validate an existing collection
|
1718 | *
|
1719 | * @param collectionNme The name of the collection to validate
|
1720 | * @param options Optional settings
|
1721 | * @param callback The command result callback
|
1722 | * @returns Promise if no callback is passed
|
1723 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Admin.html#validateCollection
|
1724 | */
|
1725 | validateCollection(collectionNme: string, callback: MongoCallback<any>): void;
|
1726 | validateCollection(collectionNme: string, options?: object): Promise<any>;
|
1727 | validateCollection(collectionNme: string, options: object, callback: MongoCallback<any>): void;
|
1728 | }
|
1729 |
|
1730 | /**
|
1731 | * Options for adding a user to the database
|
1732 | *
|
1733 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Admin.html#addUser
|
1734 | */
|
1735 | export interface AddUserOptions extends CommonOptions {
|
1736 | fsync: boolean;
|
1737 | customData?: object;
|
1738 | roles?: object[];
|
1739 | }
|
1740 |
|
1741 | /**
|
1742 | * Options for removing a user from the database
|
1743 | *
|
1744 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Admin.html#removeUser
|
1745 | */
|
1746 | export interface FSyncOptions extends CommonOptions {
|
1747 | fsync?: boolean;
|
1748 | }
|
1749 |
|
1750 | // TypeScript Omit (Exclude to be specific) does not work for objects with an "any" indexed type, and breaks discriminated unions
|
1751 | type EnhancedOmit<T, K> = string | number extends keyof T
|
1752 | ? T // T has indexed type e.g. { _id: string; [k: string]: any; } or it is "any"
|
1753 | : T extends any
|
1754 | ? Pick<T, Exclude<keyof T, K>> // discriminated unions
|
1755 | : never;
|
1756 |
|
1757 | type ExtractIdType<TSchema> = TSchema extends { _id: infer U } // user has defined a type for _id
|
1758 | ? {} extends U
|
1759 | ? Exclude<U, {}>
|
1760 | : unknown extends U
|
1761 | ? ObjectId
|
1762 | : U
|
1763 | : ObjectId; // user has not defined _id on schema
|
1764 |
|
1765 | // this makes _id optional
|
1766 | export type OptionalId<TSchema extends { _id?: any }> = ObjectId extends TSchema["_id"]
|
1767 | ? // a Schema with ObjectId _id type or "any" or "indexed type" provided
|
1768 | EnhancedOmit<TSchema, "_id"> & { _id?: ExtractIdType<TSchema> }
|
1769 | : // a Schema provided but _id type is not ObjectId
|
1770 | WithId<TSchema>;
|
1771 |
|
1772 | // this adds _id as a required property
|
1773 | export type WithId<TSchema> = EnhancedOmit<TSchema, "_id"> & { _id: ExtractIdType<TSchema> };
|
1774 |
|
1775 | /**
|
1776 | * Create a new Collection instance (INTERNAL TYPE, do not instantiate directly)
|
1777 | *
|
1778 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html
|
1779 | */
|
1780 | export interface Collection<TSchema extends { [key: string]: any } = DefaultSchema> {
|
1781 | /**
|
1782 | * Get the collection name.
|
1783 | */
|
1784 | collectionName: string;
|
1785 | /**
|
1786 | * Get the full collection namespace.
|
1787 | */
|
1788 | namespace: string;
|
1789 | /**
|
1790 | * The current write concern values.
|
1791 | */
|
1792 | writeConcern: WriteConcern;
|
1793 | /**
|
1794 | * The current read concern values.
|
1795 | */
|
1796 | readConcern: ReadConcern;
|
1797 | /**
|
1798 | * Get current index hint for collection.
|
1799 | */
|
1800 | hint: any;
|
1801 | /**
|
1802 | * Execute an aggregation framework pipeline against the collection, needs MongoDB >= 2.2
|
1803 | *
|
1804 | * @param pipeline Array containing all the aggregation framework commands for the execution
|
1805 | * @param options Optional settings
|
1806 | * @param callback The command result callback
|
1807 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#aggregate
|
1808 | */
|
1809 | aggregate<T = TSchema>(callback: MongoCallback<AggregationCursor<T>>): AggregationCursor<T>;
|
1810 | aggregate<T = TSchema>(pipeline: object[], callback: MongoCallback<AggregationCursor<T>>): AggregationCursor<T>;
|
1811 | aggregate<T = TSchema>(
|
1812 | pipeline?: object[],
|
1813 | options?: CollectionAggregationOptions,
|
1814 | callback?: MongoCallback<AggregationCursor<T>>,
|
1815 | ): AggregationCursor<T>;
|
1816 | /**
|
1817 | * Perform a bulkWrite operation without a fluent API
|
1818 | * If documents passed in do not contain the **_id** field,
|
1819 | * one will be added to each of the documents missing it by the driver, mutating the document. This behavior
|
1820 | * can be overridden by setting the **forceServerObjectId** flag.
|
1821 | *
|
1822 | * @param operations Bulk operations to perform
|
1823 | * @param options Optional settings
|
1824 | * @param callback The command result callback
|
1825 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#bulkWrite
|
1826 | */
|
1827 | bulkWrite(operations: Array<BulkWriteOperation<TSchema>>, callback: MongoCallback<BulkWriteOpResultObject>): void;
|
1828 | bulkWrite(
|
1829 | operations: Array<BulkWriteOperation<TSchema>>,
|
1830 | options?: CollectionBulkWriteOptions,
|
1831 | ): Promise<BulkWriteOpResultObject>;
|
1832 | bulkWrite(
|
1833 | operations: Array<BulkWriteOperation<TSchema>>,
|
1834 | options: CollectionBulkWriteOptions,
|
1835 | callback: MongoCallback<BulkWriteOpResultObject>,
|
1836 | ): void;
|
1837 | /**
|
1838 | * An estimated count of matching documents in the db to a query.
|
1839 | *
|
1840 | * @param query The query for the count
|
1841 | * @param options Optional settings
|
1842 | * @param callback The command result callback
|
1843 | * @returns Promise if no callback is passed
|
1844 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#count
|
1845 | * @deprecated Use `countDocuments` or `estimatedDocumentCount`
|
1846 | */
|
1847 | count(callback: MongoCallback<number>): void;
|
1848 | count(query: FilterQuery<TSchema>, callback: MongoCallback<number>): void;
|
1849 | count(query?: FilterQuery<TSchema>, options?: MongoCountPreferences): Promise<number>;
|
1850 | count(query: FilterQuery<TSchema>, options: MongoCountPreferences, callback: MongoCallback<number>): void;
|
1851 | /**
|
1852 | * Gets the number of documents matching the filter
|
1853 | * For a fast count of the total documents in a collection see `estimatedDocumentCount`.
|
1854 | *
|
1855 | * @param query The query for the count
|
1856 | * @param options Optional settings
|
1857 | * @param callback The command result callback
|
1858 | * @returns Promise if no callback is passed
|
1859 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#countDocuments
|
1860 | */
|
1861 | countDocuments(callback: MongoCallback<number>): void;
|
1862 | countDocuments(query: FilterQuery<TSchema>, callback: MongoCallback<number>): void;
|
1863 | countDocuments(query?: FilterQuery<TSchema>, options?: MongoCountPreferences): Promise<number>;
|
1864 | countDocuments(query: FilterQuery<TSchema>, options: MongoCountPreferences, callback: MongoCallback<number>): void;
|
1865 | /**
|
1866 | * Creates an index on the db and collection collection.
|
1867 | *
|
1868 | * @param fieldOrSpec Defines the index
|
1869 | * @param options Optional settings
|
1870 | * @param callback The command result callback
|
1871 | * @returns Promise if no callback is passed
|
1872 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#createIndex
|
1873 | */
|
1874 | createIndex(fieldOrSpec: string | any, callback: MongoCallback<string>): void;
|
1875 | createIndex(fieldOrSpec: string | any, options?: IndexOptions): Promise<string>;
|
1876 | createIndex(fieldOrSpec: string | any, options: IndexOptions, callback: MongoCallback<string>): void;
|
1877 | /**
|
1878 | * Creates multiple indexes in the collection, this method is only supported for MongoDB 2.6 or higher.
|
1879 | * Earlier version of MongoDB will throw a command not supported error.
|
1880 | * **Note:** Unlike `createIndex`, this function takes in raw index specifications.
|
1881 | * Index specifications are defined {@link http://docs.mongodb.org/manual/reference/command/createIndexes/ here}.
|
1882 | *
|
1883 | * @param indexSpecs An array of index specifications to be created
|
1884 | * @param options Optional settings
|
1885 | * @param callback The command result callback
|
1886 | * @returns Promise if no callback is passed
|
1887 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#createIndexes
|
1888 | */
|
1889 | createIndexes(indexSpecs: IndexSpecification[], callback: MongoCallback<any>): void;
|
1890 | createIndexes(indexSpecs: IndexSpecification[], options?: { session?: ClientSession }): Promise<any>;
|
1891 | createIndexes(
|
1892 | indexSpecs: IndexSpecification[],
|
1893 | options: { session?: ClientSession },
|
1894 | callback: MongoCallback<any>,
|
1895 | ): void;
|
1896 | /**
|
1897 | * Delete multiple documents from a collection
|
1898 | *
|
1899 | * @param filter The Filter used to select the documents to remove
|
1900 | * @param options Optional settings
|
1901 | * @param callback The command result callback
|
1902 | * @returns Promise if no callback is passed
|
1903 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#deleteMany
|
1904 | */
|
1905 | deleteMany(filter: FilterQuery<TSchema>, callback: MongoCallback<DeleteWriteOpResultObject>): void;
|
1906 | deleteMany(filter: FilterQuery<TSchema>, options?: CommonOptions): Promise<DeleteWriteOpResultObject>;
|
1907 | deleteMany(
|
1908 | filter: FilterQuery<TSchema>,
|
1909 | options: CommonOptions,
|
1910 | callback: MongoCallback<DeleteWriteOpResultObject>,
|
1911 | ): void;
|
1912 | /**
|
1913 | * Delete a document from a collection
|
1914 | *
|
1915 | * @param filter The Filter used to select the document to remove
|
1916 | * @param options Optional settings
|
1917 | * @param callback The command result callback
|
1918 | * @returns Promise if no callback is passed
|
1919 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#deleteOne
|
1920 | */
|
1921 | deleteOne(filter: FilterQuery<TSchema>, callback: MongoCallback<DeleteWriteOpResultObject>): void;
|
1922 | deleteOne(
|
1923 | filter: FilterQuery<TSchema>,
|
1924 | options?: CommonOptions & { bypassDocumentValidation?: boolean },
|
1925 | ): Promise<DeleteWriteOpResultObject>;
|
1926 | deleteOne(
|
1927 | filter: FilterQuery<TSchema>,
|
1928 | options: CommonOptions & { bypassDocumentValidation?: boolean },
|
1929 | callback: MongoCallback<DeleteWriteOpResultObject>,
|
1930 | ): void;
|
1931 | /**
|
1932 | * The distinct command returns a list of distinct values for the given key across a collection.
|
1933 | *
|
1934 | * @param key Field of the document to find distinct values for.
|
1935 | * @param query The optional query for filtering the set of documents to which we apply the distinct filter.
|
1936 | * @param options Optional settings
|
1937 | * @param callback The command result callback
|
1938 | * @returns Promise if no callback is passed
|
1939 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#distinct
|
1940 | */
|
1941 | distinct<Key extends keyof WithId<TSchema>>(
|
1942 | key: Key,
|
1943 | callback: MongoCallback<Array<FlattenIfArray<WithId<TSchema>[Key]>>>,
|
1944 | ): void;
|
1945 | distinct<Key extends keyof WithId<TSchema>>(
|
1946 | key: Key,
|
1947 | query: FilterQuery<TSchema>,
|
1948 | callback: MongoCallback<Array<FlattenIfArray<WithId<TSchema>[Key]>>>,
|
1949 | ): void;
|
1950 | distinct<Key extends keyof WithId<TSchema>>(
|
1951 | key: Key,
|
1952 | query?: FilterQuery<TSchema>,
|
1953 | options?: MongoDistinctPreferences,
|
1954 | ): Promise<Array<FlattenIfArray<WithId<TSchema>[Key]>>>;
|
1955 | distinct<Key extends keyof WithId<TSchema>>(
|
1956 | key: Key,
|
1957 | query: FilterQuery<TSchema>,
|
1958 | options: MongoDistinctPreferences,
|
1959 | callback: MongoCallback<Array<FlattenIfArray<WithId<TSchema>[Key]>>>,
|
1960 | ): void;
|
1961 | distinct(key: string, callback: MongoCallback<any[]>): void;
|
1962 | distinct(key: string, query: FilterQuery<TSchema>, callback: MongoCallback<any[]>): void;
|
1963 | distinct(key: string, query?: FilterQuery<TSchema>, options?: MongoDistinctPreferences): Promise<any[]>;
|
1964 | distinct(
|
1965 | key: string,
|
1966 | query: FilterQuery<TSchema>,
|
1967 | options: MongoDistinctPreferences,
|
1968 | callback: MongoCallback<any[]>,
|
1969 | ): void;
|
1970 | /**
|
1971 | * Drop the collection from the database, removing it permanently. New accesses will create a new collection.
|
1972 | *
|
1973 | * @param options Optional settings
|
1974 | * @param callback The command result callback
|
1975 | * @returns Promise if no callback is passed
|
1976 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#drop
|
1977 | */
|
1978 | drop(options?: { session: ClientSession }): Promise<any>;
|
1979 | drop(callback: MongoCallback<any>): void;
|
1980 | drop(options: { session: ClientSession }, callback: MongoCallback<any>): void;
|
1981 | /**
|
1982 | * Drops an index from this collection.
|
1983 | *
|
1984 | * @param indexName Name of the index to drop.
|
1985 | * @param options Optional settings
|
1986 | * @param callback The command result callback
|
1987 | * @returns Promise if no callback is passed
|
1988 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#dropIndex
|
1989 | */
|
1990 | dropIndex(indexName: string, callback: MongoCallback<any>): void;
|
1991 | dropIndex(indexName: string, options?: CommonOptions & { maxTimeMS?: number }): Promise<any>;
|
1992 | dropIndex(indexName: string, options: CommonOptions & { maxTimeMS?: number }, callback: MongoCallback<any>): void;
|
1993 | /**
|
1994 | * Drops all indexes from this collection.
|
1995 | *
|
1996 | * @param options Optional settings
|
1997 | * @param callback The command result callback
|
1998 | * @returns Promise if no callback is passed
|
1999 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#dropIndexes
|
2000 | */
|
2001 | dropIndexes(options?: { session?: ClientSession; maxTimeMS?: number }): Promise<any>;
|
2002 | dropIndexes(callback?: MongoCallback<any>): void;
|
2003 | dropIndexes(options: { session?: ClientSession; maxTimeMS?: number }, callback: MongoCallback<any>): void;
|
2004 | /**
|
2005 | * Gets an estimate of the count of documents in a collection using collection metadata.
|
2006 | *
|
2007 | * @param options Optional settings
|
2008 | * @param callback The command result callback
|
2009 | * @returns Promise if no callback is passed
|
2010 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#estimatedDocumentCount
|
2011 | */
|
2012 | estimatedDocumentCount(callback: MongoCallback<number>): void;
|
2013 | estimatedDocumentCount(query: FilterQuery<TSchema>, callback: MongoCallback<number>): void;
|
2014 | estimatedDocumentCount(query?: FilterQuery<TSchema>, options?: MongoCountPreferences): Promise<number>;
|
2015 | estimatedDocumentCount(
|
2016 | query: FilterQuery<TSchema>,
|
2017 | options: MongoCountPreferences,
|
2018 | callback: MongoCallback<number>,
|
2019 | ): void;
|
2020 | /**
|
2021 | * Creates a cursor for a query that can be used to iterate over results from MongoDB
|
2022 | *
|
2023 | * @param query The cursor query object
|
2024 | * @param options Optional settings
|
2025 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#find
|
2026 | */
|
2027 | find(query?: FilterQuery<TSchema>): Cursor<TSchema>;
|
2028 | find(query: FilterQuery<TSchema>, options?: WithoutProjection<FindOneOptions<TSchema>>): Cursor<TSchema>;
|
2029 | find<T = TSchema>(query: FilterQuery<TSchema>, options: FindOneOptions<T extends TSchema ? TSchema : T>): Cursor<T>;
|
2030 | /**
|
2031 | * Fetches the first document that matches the query
|
2032 | *
|
2033 | * @param query Query for find Operation
|
2034 | * @param options Optional settings
|
2035 | * @param callback The command result callback
|
2036 | * @returns Promise if no callback is passed
|
2037 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#findOne
|
2038 | */
|
2039 | findOne(filter: FilterQuery<TSchema>, callback: MongoCallback<TSchema>): void;
|
2040 | findOne(
|
2041 | filter: FilterQuery<TSchema>,
|
2042 | options?: WithoutProjection<FindOneOptions<TSchema>>,
|
2043 | ): Promise<TSchema | null>;
|
2044 | findOne<T = TSchema>(
|
2045 | filter: FilterQuery<TSchema>,
|
2046 | options?: FindOneOptions<T extends TSchema ? TSchema : T>,
|
2047 | ): Promise<T | null>;
|
2048 | findOne(
|
2049 | filter: FilterQuery<TSchema>,
|
2050 | options: WithoutProjection<FindOneOptions<TSchema>>,
|
2051 | callback: MongoCallback<TSchema | null>,
|
2052 | ): void;
|
2053 | findOne<T = TSchema>(
|
2054 | filter: FilterQuery<TSchema>,
|
2055 | options: FindOneOptions<T extends TSchema ? TSchema : T>,
|
2056 | callback: MongoCallback<T extends TSchema ? TSchema : T | null>,
|
2057 | ): void;
|
2058 | /**
|
2059 | * Find a document and delete it in one atomic operation. Requires a write lock for the duration of the operation.
|
2060 | *
|
2061 | * @param filter The Filter used to select the document to remove
|
2062 | * @param options Optional settings
|
2063 | * @param callback The command result callback
|
2064 | * @returns Promise if no callback is passed
|
2065 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#findOneAndDelete
|
2066 | */
|
2067 | findOneAndDelete(
|
2068 | filter: FilterQuery<TSchema>,
|
2069 | callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>,
|
2070 | ): void;
|
2071 | findOneAndDelete(
|
2072 | filter: FilterQuery<TSchema>,
|
2073 | options?: FindOneAndDeleteOption<TSchema>,
|
2074 | ): Promise<FindAndModifyWriteOpResultObject<TSchema>>;
|
2075 | findOneAndDelete(
|
2076 | filter: FilterQuery<TSchema>,
|
2077 | options: FindOneAndDeleteOption<TSchema>,
|
2078 | callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>,
|
2079 | ): void;
|
2080 | /**
|
2081 | * Find a document and replace it in one atomic operation. Requires a write lock for the duration of the operation.
|
2082 | *
|
2083 | * @param filter The Filter used to select the document to replace
|
2084 | * @param replacement The Document that replaces the matching document
|
2085 | * @param options Optional settings
|
2086 | * @param callback The command result callback
|
2087 | * @returns Promise if no callback is passed
|
2088 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#findOneAndReplace
|
2089 | */
|
2090 | findOneAndReplace(
|
2091 | filter: FilterQuery<TSchema>,
|
2092 | replacement: object,
|
2093 | callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>,
|
2094 | ): void;
|
2095 | findOneAndReplace(
|
2096 | filter: FilterQuery<TSchema>,
|
2097 | replacement: object,
|
2098 | options?: FindOneAndReplaceOption<TSchema>,
|
2099 | ): Promise<FindAndModifyWriteOpResultObject<TSchema>>;
|
2100 | findOneAndReplace(
|
2101 | filter: FilterQuery<TSchema>,
|
2102 | replacement: object,
|
2103 | options: FindOneAndReplaceOption<TSchema>,
|
2104 | callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>,
|
2105 | ): void;
|
2106 | /**
|
2107 | * Find a document and update it in one atomic operation. Requires a write lock for the duration of the operation.
|
2108 | *
|
2109 | * @param filter The Filter used to select the document to update
|
2110 | * @param update Update operations to be performed on the document
|
2111 | * @param options Optional settings
|
2112 | * @param callback The command result callback
|
2113 | * @returns Promise if no callback is passed
|
2114 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#findOneAndUpdate
|
2115 | */
|
2116 | findOneAndUpdate(
|
2117 | filter: FilterQuery<TSchema>,
|
2118 | update: UpdateQuery<TSchema> | TSchema,
|
2119 | callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>,
|
2120 | ): void;
|
2121 | findOneAndUpdate(
|
2122 | filter: FilterQuery<TSchema>,
|
2123 | update: UpdateQuery<TSchema> | TSchema,
|
2124 | options?: FindOneAndUpdateOption<TSchema>,
|
2125 | ): Promise<FindAndModifyWriteOpResultObject<TSchema>>;
|
2126 | findOneAndUpdate(
|
2127 | filter: FilterQuery<TSchema>,
|
2128 | update: UpdateQuery<TSchema> | TSchema,
|
2129 | options: FindOneAndUpdateOption<TSchema>,
|
2130 | callback: MongoCallback<FindAndModifyWriteOpResultObject<TSchema>>,
|
2131 | ): void;
|
2132 | /**
|
2133 | * Execute a geo search using a geo haystack index on a collection.
|
2134 | *
|
2135 | * @param x Point to search on the x axis, ensure the indexes are ordered in the same order.
|
2136 | * @param y Point to search on the y axis, ensure the indexes are ordered in the same order.
|
2137 | * @param options Optional settings
|
2138 | * @param callback The command result callback
|
2139 | * @returns Promise if no callback is passed
|
2140 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#geoHaystackSearch
|
2141 | * @deprecated See {@link https://docs.mongodb.com/v3.6/geospatial-queries/ geospatial queries docs} for current geospatial support
|
2142 | */
|
2143 | geoHaystackSearch(x: number, y: number, callback: MongoCallback<any>): void;
|
2144 | geoHaystackSearch(x: number, y: number, options?: GeoHaystackSearchOptions): Promise<any>;
|
2145 | geoHaystackSearch(x: number, y: number, options: GeoHaystackSearchOptions, callback: MongoCallback<any>): void;
|
2146 | /**
|
2147 | * Run a group command across a collection
|
2148 | *
|
2149 | * @param keys An object, array or function expressing the keys to group by.
|
2150 | * @param condition An optional condition that must be true for a row to be considered.
|
2151 | * @param initial Initial value of the aggregation counter object.
|
2152 | * @param reduce The reduce function aggregates (reduces) the objects iterated.
|
2153 | * @param finalize An optional function to be run on each item in the result set just before the item is returned.
|
2154 | * @param command Specify if you wish to run using the internal group command or using eval, default is true.
|
2155 | * @param options Optional settings
|
2156 | * @param callback The command result callback
|
2157 | * @returns Promise if no callback is passed
|
2158 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#group
|
2159 | * @deprecated MongoDB 3.6 or higher no longer supports the group command. We recommend rewriting using the aggregation framework.
|
2160 | */
|
2161 | group(
|
2162 | keys: object | any[] | Function | Code,
|
2163 | condition: object,
|
2164 | initial: object,
|
2165 | reduce: Function | Code,
|
2166 | finalize: Function | Code,
|
2167 | command: boolean,
|
2168 | callback: MongoCallback<any>,
|
2169 | ): void;
|
2170 | group(
|
2171 | keys: object | any[] | Function | Code,
|
2172 | condition: object,
|
2173 | initial: object,
|
2174 | reduce: Function | Code,
|
2175 | finalize: Function | Code,
|
2176 | command: boolean,
|
2177 | options?: { readPreference?: ReadPreferenceOrMode; session?: ClientSession },
|
2178 | ): Promise<any>;
|
2179 | group(
|
2180 | keys: object | any[] | Function | Code,
|
2181 | condition: object,
|
2182 | initial: object,
|
2183 | reduce: Function | Code,
|
2184 | finalize: Function | Code,
|
2185 | command: boolean,
|
2186 | options: {
|
2187 | readPreference?: ReadPreferenceOrMode;
|
2188 | session?: ClientSession;
|
2189 | },
|
2190 | callback: MongoCallback<any>,
|
2191 | ): void;
|
2192 | /**
|
2193 | * Retrieve all the indexes on the collection.
|
2194 | *
|
2195 | * @param options Optional settings
|
2196 | * @param callback The command result callback
|
2197 | * @returns Promise if no callback is passed
|
2198 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#indexes
|
2199 | */
|
2200 | indexes(options?: { session: ClientSession }): Promise<any>;
|
2201 | indexes(callback: MongoCallback<any>): void;
|
2202 | indexes(options: { session?: ClientSession }, callback: MongoCallback<any>): void;
|
2203 | /**
|
2204 | * Checks if one or more indexes exist on the collection, fails on first non-existing index
|
2205 | *
|
2206 | * @param indexes One or more index names to check.
|
2207 | * @param options Optional settings
|
2208 | * @param callback The command result callback
|
2209 | * @returns Promise if no callback is passed
|
2210 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#indexExists
|
2211 | */
|
2212 | indexExists(indexes: string | string[], callback: MongoCallback<boolean>): void;
|
2213 | indexExists(indexes: string | string[], options?: { session: ClientSession }): Promise<boolean>;
|
2214 | indexExists(
|
2215 | indexes: string | string[],
|
2216 | options: { session: ClientSession },
|
2217 | callback: MongoCallback<boolean>,
|
2218 | ): void;
|
2219 | /**
|
2220 | * Retrieves this collections index info.
|
2221 | *
|
2222 | * @param options Optional settings
|
2223 | * @param callback The command result callback
|
2224 | * @returns Promise if no callback is passed
|
2225 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#indexInformation
|
2226 | */
|
2227 | indexInformation(callback: MongoCallback<any>): void;
|
2228 | indexInformation(options?: { full: boolean; session: ClientSession }): Promise<any>;
|
2229 | indexInformation(options: { full: boolean; session: ClientSession }, callback: MongoCallback<any>): void;
|
2230 | /**
|
2231 | * Initiate an In order bulk write operation. Operations will be serially executed in the order they are added, creating a new operation for each switch in types.
|
2232 | *
|
2233 | * @param options Optional settings
|
2234 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#initializeOrderedBulkOp
|
2235 | */
|
2236 | initializeOrderedBulkOp(options?: CommonOptions): OrderedBulkOperation;
|
2237 | /**
|
2238 | * Initiate an Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order.
|
2239 | *
|
2240 | * @param options Optional settings
|
2241 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#initializeUnorderedBulkOp
|
2242 | */
|
2243 | initializeUnorderedBulkOp(options?: CommonOptions): UnorderedBulkOperation;
|
2244 | /**
|
2245 | * Inserts a single document or a an array of documents into MongoDB. If documents passed in do not contain the **_id** field,
|
2246 | * one will be added to each of the documents missing it by the driver, mutating the document. This behavior
|
2247 | * can be overridden by setting the **forceServerObjectId** flag.
|
2248 | *
|
2249 | * @param docs Documents to insert.
|
2250 | * @param options Optional settings
|
2251 | * @param callback The command result callback
|
2252 | * @returns Promise if no callback is passed
|
2253 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#insert
|
2254 | * @deprecated Use insertOne, insertMany or bulkWrite
|
2255 | */
|
2256 | insert(docs: OptionalId<TSchema>, callback: MongoCallback<InsertWriteOpResult<WithId<TSchema>>>): void;
|
2257 | insert(
|
2258 | docs: OptionalId<TSchema>,
|
2259 | options?: CollectionInsertOneOptions,
|
2260 | ): Promise<InsertWriteOpResult<WithId<TSchema>>>;
|
2261 | insert(
|
2262 | docs: OptionalId<TSchema>,
|
2263 | options: CollectionInsertOneOptions,
|
2264 | callback: MongoCallback<InsertWriteOpResult<WithId<TSchema>>>,
|
2265 | ): void;
|
2266 | /**
|
2267 | * Inserts an array of documents into MongoDB. If documents passed in do not contain the **_id** field,
|
2268 | * one will be added to each of the documents missing it by the driver, mutating the document. This behavior
|
2269 | * can be overridden by setting the **forceServerObjectId** flag.
|
2270 | *
|
2271 | * @param docs Documents to insert.
|
2272 | * @param options Optional settings
|
2273 | * @param callback The command result callback
|
2274 | * @returns Promise if no callback is passed
|
2275 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#insertMany
|
2276 | */
|
2277 | insertMany(docs: Array<OptionalId<TSchema>>, callback: MongoCallback<InsertWriteOpResult<WithId<TSchema>>>): void;
|
2278 | insertMany(
|
2279 | docs: Array<OptionalId<TSchema>>,
|
2280 | options?: CollectionInsertManyOptions,
|
2281 | ): Promise<InsertWriteOpResult<WithId<TSchema>>>;
|
2282 | insertMany(
|
2283 | docs: Array<OptionalId<TSchema>>,
|
2284 | options: CollectionInsertManyOptions,
|
2285 | callback: MongoCallback<InsertWriteOpResult<WithId<TSchema>>>,
|
2286 | ): void;
|
2287 | /**
|
2288 | * Inserts a single document into MongoDB. If documents passed in do not contain the **_id** field,
|
2289 | * one will be added to each of the documents missing it by the driver, mutating the document. This behavior
|
2290 | * can be overridden by setting the **forceServerObjectId** flag.
|
2291 | *
|
2292 | * @param doc Document to insert.
|
2293 | * @param options Optional settings
|
2294 | * @param callback The command result callback
|
2295 | * @returns Promise if no callback is passed
|
2296 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#insertOne
|
2297 | */
|
2298 | insertOne(docs: OptionalId<TSchema>, callback: MongoCallback<InsertOneWriteOpResult<WithId<TSchema>>>): void;
|
2299 | insertOne(
|
2300 | docs: OptionalId<TSchema>,
|
2301 | options?: CollectionInsertOneOptions,
|
2302 | ): Promise<InsertOneWriteOpResult<WithId<TSchema>>>;
|
2303 | insertOne(
|
2304 | docs: OptionalId<TSchema>,
|
2305 | options: CollectionInsertOneOptions,
|
2306 | callback: MongoCallback<InsertOneWriteOpResult<WithId<TSchema>>>,
|
2307 | ): void;
|
2308 | /**
|
2309 | * Returns if the collection is a capped collection
|
2310 | *
|
2311 | * @param options Optional settings
|
2312 | * @param callback The command result callback
|
2313 | * @returns Promise if no callback is passed
|
2314 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#isCapped
|
2315 | */
|
2316 | isCapped(options?: { session: ClientSession }): Promise<any>;
|
2317 | isCapped(callback: MongoCallback<any>): void;
|
2318 | isCapped(options: { session: ClientSession }, callback: MongoCallback<any>): void;
|
2319 | /**
|
2320 | * Get the list of all indexes information for the collection.
|
2321 | *
|
2322 | * @param options Optional settings
|
2323 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#listIndexes
|
2324 | */
|
2325 | listIndexes(options?: {
|
2326 | batchSize?: number;
|
2327 | readPreference?: ReadPreferenceOrMode;
|
2328 | session?: ClientSession;
|
2329 | }): CommandCursor;
|
2330 | /**
|
2331 | * Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.
|
2332 | *
|
2333 | * @param map The mapping function.
|
2334 | * @param reduce The reduce function.
|
2335 | * @param options Optional settings
|
2336 | * @param callback The command result callback
|
2337 | * @returns Promise if no callback is passed
|
2338 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#mapReduce
|
2339 | */
|
2340 | mapReduce<TKey, TValue>(
|
2341 | map: CollectionMapFunction<TSchema> | string,
|
2342 | reduce: CollectionReduceFunction<TKey, TValue> | string,
|
2343 | callback: MongoCallback<any>,
|
2344 | ): void;
|
2345 | mapReduce<TKey, TValue>(
|
2346 | map: CollectionMapFunction<TSchema> | string,
|
2347 | reduce: CollectionReduceFunction<TKey, TValue> | string,
|
2348 | options?: MapReduceOptions,
|
2349 | ): Promise<any>;
|
2350 | mapReduce<TKey, TValue>(
|
2351 | map: CollectionMapFunction<TSchema> | string,
|
2352 | reduce: CollectionReduceFunction<TKey, TValue> | string,
|
2353 | options: MapReduceOptions,
|
2354 | callback: MongoCallback<any>,
|
2355 | ): void;
|
2356 | /**
|
2357 | * Returns the options of the collection.
|
2358 | *
|
2359 | * @param options Optional settings
|
2360 | * @param callback The command result callback
|
2361 | * @returns Promise if no callback is passed
|
2362 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#options
|
2363 | */
|
2364 | options(options?: { session: ClientSession }): Promise<any>;
|
2365 | options(callback: MongoCallback<any>): void;
|
2366 | options(options: { session: ClientSession }, callback: MongoCallback<any>): void;
|
2367 | /**
|
2368 | * Return N number of parallel cursors for a collection allowing parallel reading of entire collection. There are
|
2369 | * no ordering guarantees for returned results.
|
2370 | *
|
2371 | * @param options Optional settings
|
2372 | * @param callback The command result callback
|
2373 | * @returns Promise if no callback is passed
|
2374 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#parallelCollectionScan
|
2375 | */
|
2376 | parallelCollectionScan(callback: MongoCallback<Array<Cursor<any>>>): void;
|
2377 | parallelCollectionScan(options?: ParallelCollectionScanOptions): Promise<Array<Cursor<any>>>;
|
2378 | parallelCollectionScan(options: ParallelCollectionScanOptions, callback: MongoCallback<Array<Cursor<any>>>): void;
|
2379 | /**
|
2380 | * Reindex all indexes on the collection
|
2381 | * Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.
|
2382 | *
|
2383 | * @param options Optional settings
|
2384 | * @param callback The command result callback
|
2385 | * @returns Promise if no callback is passed
|
2386 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#reIndex
|
2387 | * @deprecated use db.command instead
|
2388 | */
|
2389 | reIndex(options?: { session: ClientSession }): Promise<any>;
|
2390 | reIndex(callback: MongoCallback<any>): void;
|
2391 | reIndex(options: { session: ClientSession }, callback: MongoCallback<any>): void;
|
2392 | /**
|
2393 | * Remove documents.
|
2394 | *
|
2395 | * @param selector The selector for the update operation.
|
2396 | * @param options Optional settings
|
2397 | * @param callback The command result callback
|
2398 | * @returns Promise if no callback is passed
|
2399 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#remove
|
2400 | * @deprecated Use use deleteOne, deleteMany or bulkWrite
|
2401 | */
|
2402 | remove(selector: object, callback: MongoCallback<WriteOpResult>): void;
|
2403 | remove(selector: object, options?: CommonOptions & { single?: boolean }): Promise<WriteOpResult>;
|
2404 | remove(
|
2405 | selector: object,
|
2406 | options?: CommonOptions & { single?: boolean },
|
2407 | callback?: MongoCallback<WriteOpResult>,
|
2408 | ): void;
|
2409 | /**
|
2410 | * Rename the collection
|
2411 | *
|
2412 | * @param newName New name of of the collection.
|
2413 | * @param options Optional settings
|
2414 | * @param callback The command result callback
|
2415 | * @returns Promise if no callback is passed
|
2416 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#rename
|
2417 | */
|
2418 | rename(newName: string, callback: MongoCallback<Collection<TSchema>>): void;
|
2419 | rename(newName: string, options?: { dropTarget?: boolean; session?: ClientSession }): Promise<Collection<TSchema>>;
|
2420 | rename(
|
2421 | newName: string,
|
2422 | options: { dropTarget?: boolean; session?: ClientSession },
|
2423 | callback: MongoCallback<Collection<TSchema>>,
|
2424 | ): void;
|
2425 | /**
|
2426 | * Replace a document in a collection with another document
|
2427 | *
|
2428 | * @param filter The Filter used to select the document to replace
|
2429 | * @param doc The Document that replaces the matching document
|
2430 | * @param options Optional settings
|
2431 | * @param callback The command result callback
|
2432 | * @returns Promise if no callback is passed
|
2433 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#replaceOne
|
2434 | */
|
2435 | replaceOne(filter: FilterQuery<TSchema>, doc: TSchema, callback: MongoCallback<ReplaceWriteOpResult>): void;
|
2436 | replaceOne(filter: FilterQuery<TSchema>, doc: TSchema, options?: ReplaceOneOptions): Promise<ReplaceWriteOpResult>;
|
2437 | replaceOne(
|
2438 | filter: FilterQuery<TSchema>,
|
2439 | doc: TSchema,
|
2440 | options: ReplaceOneOptions,
|
2441 | callback: MongoCallback<ReplaceWriteOpResult>,
|
2442 | ): void;
|
2443 | /**
|
2444 | * Save a document. Simple full document replacement function. Not recommended for efficiency, use atomic
|
2445 | * operators and update instead for more efficient operations.
|
2446 | *
|
2447 | * @param doc Document to save
|
2448 | * @param options Optional settings
|
2449 | * @param callback The command result callback
|
2450 | * @returns Promise if no callback is passed
|
2451 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#save
|
2452 | * @deprecated Use insertOne, insertMany, updateOne or updateMany
|
2453 | */
|
2454 | save(doc: TSchema, callback: MongoCallback<WriteOpResult>): void;
|
2455 | save(doc: TSchema, options?: CommonOptions): Promise<WriteOpResult>;
|
2456 | save(doc: TSchema, options: CommonOptions, callback: MongoCallback<WriteOpResult>): void;
|
2457 | /**
|
2458 | * Get all the collection statistics.
|
2459 | *
|
2460 | * @param options Optional settings
|
2461 | * @param callback The command result callback
|
2462 | * @returns Promise if no callback is passed
|
2463 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#stats
|
2464 | */
|
2465 | stats(callback: MongoCallback<CollStats>): void;
|
2466 | stats(options?: { scale: number; session?: ClientSession }): Promise<CollStats>;
|
2467 | stats(options: { scale: number; session?: ClientSession }, callback: MongoCallback<CollStats>): void;
|
2468 | /**
|
2469 | * Updates documents
|
2470 | *
|
2471 | * @param selector The selector for the update operation.
|
2472 | * @param update The update operations to be applied to the documents
|
2473 | * @param options Optional settings
|
2474 | * @param callback The command result callback
|
2475 | * @returns Promise if no callback is passed
|
2476 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#update
|
2477 | * @deprecated use updateOne, updateMany or bulkWrite
|
2478 | */
|
2479 | update(
|
2480 | filter: FilterQuery<TSchema>,
|
2481 | update: UpdateQuery<TSchema> | Partial<TSchema>,
|
2482 | callback: MongoCallback<WriteOpResult>,
|
2483 | ): void;
|
2484 | update(
|
2485 | filter: FilterQuery<TSchema>,
|
2486 | update: UpdateQuery<TSchema> | Partial<TSchema>,
|
2487 | options?: UpdateOneOptions & { multi?: boolean },
|
2488 | ): Promise<WriteOpResult>;
|
2489 | update(
|
2490 | filter: FilterQuery<TSchema>,
|
2491 | update: UpdateQuery<TSchema> | Partial<TSchema>,
|
2492 | options: UpdateOneOptions & { multi?: boolean },
|
2493 | callback: MongoCallback<WriteOpResult>,
|
2494 | ): void;
|
2495 | /**
|
2496 | * Update multiple documents in a collection
|
2497 | *
|
2498 | * @param filter The Filter used to select the documents to update
|
2499 | * @param update The update operations to be applied to the documents
|
2500 | * @param options Optional settings
|
2501 | * @param callback The command result callback
|
2502 | * @returns Promise if no callback is passed
|
2503 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#updateMany
|
2504 | */
|
2505 | updateMany(
|
2506 | filter: FilterQuery<TSchema>,
|
2507 | update: UpdateQuery<TSchema> | Partial<TSchema>,
|
2508 | callback: MongoCallback<UpdateWriteOpResult>,
|
2509 | ): void;
|
2510 | updateMany(
|
2511 | filter: FilterQuery<TSchema>,
|
2512 | update: UpdateQuery<TSchema> | Partial<TSchema>,
|
2513 | options?: UpdateManyOptions,
|
2514 | ): Promise<UpdateWriteOpResult>;
|
2515 | updateMany(
|
2516 | filter: FilterQuery<TSchema>,
|
2517 | update: UpdateQuery<TSchema> | Partial<TSchema>,
|
2518 | options: UpdateManyOptions,
|
2519 | callback: MongoCallback<UpdateWriteOpResult>,
|
2520 | ): void;
|
2521 | /**
|
2522 | * Update a single document in a collection
|
2523 | *
|
2524 | * @param filter The Filter used to select the document to update
|
2525 | * @param update The update operations to be applied to the document
|
2526 | * @param options Optional settings
|
2527 | * @param callback The command result callback
|
2528 | * @returns Promise if no callback is passed
|
2529 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#updateOne
|
2530 | */
|
2531 | updateOne(
|
2532 | filter: FilterQuery<TSchema>,
|
2533 | update: UpdateQuery<TSchema> | Partial<TSchema>,
|
2534 | callback: MongoCallback<UpdateWriteOpResult>,
|
2535 | ): void;
|
2536 | updateOne(
|
2537 | filter: FilterQuery<TSchema>,
|
2538 | update: UpdateQuery<TSchema> | Partial<TSchema>,
|
2539 | options?: UpdateOneOptions,
|
2540 | ): Promise<UpdateWriteOpResult>;
|
2541 | updateOne(
|
2542 | filter: FilterQuery<TSchema>,
|
2543 | update: UpdateQuery<TSchema> | Partial<TSchema>,
|
2544 | options: UpdateOneOptions,
|
2545 | callback: MongoCallback<UpdateWriteOpResult>,
|
2546 | ): void;
|
2547 | /**
|
2548 | * Create a new Change Stream, watching for new changes (insertions, updates, replacements, deletions, and invalidations) in this collection.
|
2549 | *
|
2550 | * @param pipeline An array of {@link https://docs.mongodb.com/v3.6/reference/operator/aggregation-pipeline/ aggregation pipeline stages}
|
2551 | * through which to pass change stream documents. This allows for filtering (using `$match`) and manipulating the change stream documents.
|
2552 | * @param options Optional settings
|
2553 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#watch
|
2554 | */
|
2555 | watch<T = TSchema>(
|
2556 | pipeline?: object[],
|
2557 | options?: ChangeStreamOptions & { session?: ClientSession },
|
2558 | ): ChangeStream<T>;
|
2559 | watch<T = TSchema>(options?: ChangeStreamOptions & { session?: ClientSession }): ChangeStream<T>;
|
2560 | }
|
2561 |
|
2562 | /** Update Query */
|
2563 | type KeysOfAType<TSchema, Type> = {
|
2564 | [key in keyof TSchema]: NonNullable<TSchema[key]> extends Type ? key : never;
|
2565 | }[keyof TSchema];
|
2566 | type KeysOfOtherType<TSchema, Type> = {
|
2567 | [key in keyof TSchema]: NonNullable<TSchema[key]> extends Type ? never : key;
|
2568 | }[keyof TSchema];
|
2569 |
|
2570 | type AcceptedFields<TSchema, FieldType, AssignableType> = {
|
2571 | readonly [key in KeysOfAType<TSchema, FieldType>]?: AssignableType;
|
2572 | };
|
2573 |
|
2574 | /** It avoids using fields with not acceptable types */
|
2575 | type NotAcceptedFields<TSchema, FieldType> = {
|
2576 | readonly [key in KeysOfOtherType<TSchema, FieldType>]?: never;
|
2577 | };
|
2578 |
|
2579 | type DotAndArrayNotation<AssignableType> = {
|
2580 | readonly [key: string]: AssignableType;
|
2581 | };
|
2582 |
|
2583 | type ReadonlyPartial<TSchema> = {
|
2584 | readonly [key in keyof TSchema]?: TSchema[key];
|
2585 | };
|
2586 |
|
2587 | export type OnlyFieldsOfType<TSchema, FieldType = any, AssignableType = FieldType> = AcceptedFields<
|
2588 | TSchema,
|
2589 | FieldType,
|
2590 | AssignableType
|
2591 | > &
|
2592 | NotAcceptedFields<TSchema, FieldType> &
|
2593 | DotAndArrayNotation<AssignableType>;
|
2594 |
|
2595 | export type MatchKeysAndValues<TSchema> = ReadonlyPartial<TSchema> & DotAndArrayNotation<any>;
|
2596 |
|
2597 | type Unpacked<Type> = Type extends ReadonlyArray<infer Element> ? Element : Type;
|
2598 |
|
2599 | type UpdateOptionalId<T> = T extends { _id?: any } ? OptionalId<T> : T;
|
2600 |
|
2601 | export type SortValues = -1 | 1;
|
2602 |
|
2603 | /**
|
2604 | * Values for the $meta aggregation pipeline operator
|
2605 | *
|
2606 | * @see https://docs.mongodb.com/v3.6/reference/operator/aggregation/meta/#proj._S_meta
|
2607 | */
|
2608 | export type MetaSortOperators = "textScore" | "indexKey";
|
2609 |
|
2610 | export type MetaProjectionOperators =
|
2611 | | MetaSortOperators
|
2612 | /** Only for Atlas Search https://docs.atlas.mongodb.com/reference/atlas-search/scoring/ */
|
2613 | | "searchScore"
|
2614 | /** Only for Atlas Search https://docs.atlas.mongodb.com/reference/atlas-search/highlighting/ */
|
2615 | | "searchHighlights";
|
2616 |
|
2617 | export type SchemaMember<T, V> = { [P in keyof T]?: V } | { [key: string]: V };
|
2618 |
|
2619 | export type SortOptionObject<T> = SchemaMember<T, number | { $meta?: MetaSortOperators }>;
|
2620 |
|
2621 | export type AddToSetOperators<Type> = {
|
2622 | $each: Type;
|
2623 | };
|
2624 |
|
2625 | export type ArrayOperator<Type> = {
|
2626 | $each: Type;
|
2627 | $slice?: number;
|
2628 | $position?: number;
|
2629 | $sort?: SortValues | Record<string, SortValues>;
|
2630 | };
|
2631 |
|
2632 | export type SetFields<TSchema> = ({
|
2633 | readonly [key in KeysOfAType<TSchema, ReadonlyArray<any> | undefined>]?:
|
2634 | | UpdateOptionalId<Unpacked<TSchema[key]>>
|
2635 | | AddToSetOperators<Array<UpdateOptionalId<Unpacked<TSchema[key]>>>>;
|
2636 | } &
|
2637 | NotAcceptedFields<TSchema, ReadonlyArray<any> | undefined>) & {
|
2638 | readonly [key: string]: AddToSetOperators<any> | any;
|
2639 | };
|
2640 |
|
2641 | export type PushOperator<TSchema> = ({
|
2642 | readonly [key in KeysOfAType<TSchema, ReadonlyArray<any>>]?:
|
2643 | | Unpacked<TSchema[key]>
|
2644 | | ArrayOperator<Array<Unpacked<TSchema[key]>>>;
|
2645 | } &
|
2646 | NotAcceptedFields<TSchema, ReadonlyArray<any>>) & {
|
2647 | readonly [key: string]: ArrayOperator<any> | any;
|
2648 | };
|
2649 |
|
2650 | export type PullOperator<TSchema> = ({
|
2651 | readonly [key in KeysOfAType<TSchema, ReadonlyArray<any>>]?:
|
2652 | | Partial<Unpacked<TSchema[key]>>
|
2653 | | ObjectQuerySelector<Unpacked<TSchema[key]>>;
|
2654 | } &
|
2655 | NotAcceptedFields<TSchema, ReadonlyArray<any>>) & {
|
2656 | readonly [key: string]: QuerySelector<any> | any;
|
2657 | };
|
2658 |
|
2659 | export type PullAllOperator<TSchema> = ({
|
2660 | readonly [key in KeysOfAType<TSchema, ReadonlyArray<any>>]?: TSchema[key];
|
2661 | } &
|
2662 | NotAcceptedFields<TSchema, ReadonlyArray<any>>) & {
|
2663 | readonly [key: string]: any[];
|
2664 | };
|
2665 |
|
2666 | /**
|
2667 | * Modifiers to use in update operations
|
2668 | * @see https://docs.mongodb.com/v3.6/reference/operator/update
|
2669 | *
|
2670 | * @see https://docs.mongodb.com/v3.6/reference/operator/update-field/
|
2671 | * @param $currentDate Sets the value of a field to current date, either as a Date or a Timestamp.
|
2672 | * @param $inc Increments the value of the field by the specified amount.
|
2673 | * @param $min Only updates the field if the specified value is less than the existing field value.
|
2674 | * @param $max Only updates the field if the specified value is greater than the existing field value.
|
2675 | * @param $mul Multiplies the value of the field by the specified amount.
|
2676 | * @param $rename Renames a field.
|
2677 | * @param $set Sets the value of a field in a document.
|
2678 | * @param $setOnInsert Sets the value of a field if an update results in an insert of a document. Has no effect on update operations that modify existing documents.
|
2679 | * @param $unset Removes the specified field from a document.
|
2680 | *
|
2681 | * @see https://docs.mongodb.com/v3.6/reference/operator/update-array/
|
2682 | * @param $addToSet Adds elements to an array only if they do not already exist in the set.
|
2683 | * @param $pop Removes the first or last item of an array.
|
2684 | * @param $pull Removes all array elements that match a specified query.
|
2685 | * @param $push Adds an item to an array.
|
2686 | * @param $pullAll Removes all matching values from an array.
|
2687 | * @param $bit Performs bitwise `AND`, `OR`, and `XOR` updates of integer values.
|
2688 | * @see https://docs.mongodb.com/v3.6/reference/operator/update-bitwise/
|
2689 | *
|
2690 | */
|
2691 | export type UpdateQuery<TSchema> = {
|
2692 | $currentDate?: OnlyFieldsOfType<TSchema, Date | Timestamp, true | { $type: "date" | "timestamp" }>;
|
2693 | $inc?: OnlyFieldsOfType<TSchema, NumericTypes | undefined>;
|
2694 | $min?: MatchKeysAndValues<TSchema>;
|
2695 | $max?: MatchKeysAndValues<TSchema>;
|
2696 | $mul?: OnlyFieldsOfType<TSchema, NumericTypes | undefined>;
|
2697 | $rename?: { [key: string]: string };
|
2698 | $set?: MatchKeysAndValues<TSchema>;
|
2699 | $setOnInsert?: MatchKeysAndValues<TSchema>;
|
2700 | $unset?: OnlyFieldsOfType<TSchema, any, "" | 1 | true>;
|
2701 |
|
2702 | $addToSet?: SetFields<TSchema>;
|
2703 | $pop?: OnlyFieldsOfType<TSchema, ReadonlyArray<any>, 1 | -1>;
|
2704 | $pull?: PullOperator<TSchema>;
|
2705 | $push?: PushOperator<TSchema>;
|
2706 | $pullAll?: PullAllOperator<TSchema>;
|
2707 |
|
2708 | $bit?: {
|
2709 | [key: string]: { [key in "and" | "or" | "xor"]?: number };
|
2710 | };
|
2711 | };
|
2712 |
|
2713 | /**
|
2714 | * Available BSON types
|
2715 | *
|
2716 | * @see https://docs.mongodb.com/v3.6/reference/operator/query/type/#available-types
|
2717 | */
|
2718 | export enum BSONType {
|
2719 | Double = 1,
|
2720 | String,
|
2721 | Object,
|
2722 | Array,
|
2723 | BinData,
|
2724 | /** @deprecated */
|
2725 | Undefined,
|
2726 | ObjectId,
|
2727 | Boolean,
|
2728 | Date,
|
2729 | Null,
|
2730 | Regex,
|
2731 | /** @deprecated */
|
2732 | DBPointer,
|
2733 | JavaScript,
|
2734 | /** @deprecated */
|
2735 | Symbol,
|
2736 | JavaScriptWithScope,
|
2737 | Int,
|
2738 | Timestamp,
|
2739 | Long,
|
2740 | Decimal,
|
2741 | MinKey = -1,
|
2742 | MaxKey = 127,
|
2743 | }
|
2744 |
|
2745 | type BSONTypeAlias =
|
2746 | | "number"
|
2747 | | "double"
|
2748 | | "string"
|
2749 | | "object"
|
2750 | | "array"
|
2751 | | "binData"
|
2752 | | "undefined"
|
2753 | | "objectId"
|
2754 | | "bool"
|
2755 | | "date"
|
2756 | | "null"
|
2757 | | "regex"
|
2758 | | "dbPointer"
|
2759 | | "javascript"
|
2760 | | "symbol"
|
2761 | | "javascriptWithScope"
|
2762 | | "int"
|
2763 | | "timestamp"
|
2764 | | "long"
|
2765 | | "decimal"
|
2766 | | "minKey"
|
2767 | | "maxKey";
|
2768 |
|
2769 | /** @see https://docs.mongodb.com/v3.6/reference/operator/query-bitwise */
|
2770 | type BitwiseQuery =
|
2771 | | number /** <numeric bitmask> */
|
2772 | | Binary /** <BinData bitmask> */
|
2773 | | number[]; /** [ <position1>, <position2>, ... ] */
|
2774 |
|
2775 | // we can search using alternative types in mongodb e.g.
|
2776 | // string types can be searched using a regex in mongo
|
2777 | // array types can be searched using their element type
|
2778 | type RegExpForString<T> = T extends string ? RegExp | T : T;
|
2779 | type MongoAltQuery<T> = T extends ReadonlyArray<infer U> ? T | RegExpForString<U> : RegExpForString<T>;
|
2780 |
|
2781 | /**
|
2782 | * Available query selector types
|
2783 | *
|
2784 | * @param $eq Matches values that are equal to a specified value.
|
2785 | * @param $gt Matches values that are greater than a specified value.
|
2786 | * @param $gte Matches values that are greater than or equal to a specified value.
|
2787 | * @param $in Matches values that are greater than or equal to a specified value.
|
2788 | * @param $lt Matches values that are less than a specified value.
|
2789 | * @param $lte Matches values that are less than or equal to a specified value.
|
2790 | * @param $ne Matches all values that are not equal to a specified value.
|
2791 | * @param $nin Matches none of the values specified in an array.
|
2792 | *
|
2793 | * @param $and Joins query clauses with a logical `AND` returns all documents that match the conditions of both clauses.
|
2794 | * @param $not Inverts the effect of a query expression and returns documents that do not match the query expression.
|
2795 | * @param $nor Joins query clauses with a logical `NOR` returns all documents that fail to match both clauses.
|
2796 | * @param $or Joins query clauses with a logical `OR` returns all documents that match the conditions of either clause.
|
2797 | *
|
2798 | * @param $exists Matches documents that have the specified field.
|
2799 | * @param $type Selects documents if a field is of the specified type.
|
2800 | *
|
2801 | * @param $expr Allows use of aggregation expressions within the query language.
|
2802 | * @param $jsonSchema Validate documents against the given JSON Schema.
|
2803 | * @param $mod Performs a modulo operation on the value of a field and selects documents with a specified result.
|
2804 | * @param $regex Selects documents where values match a specified regular expression.
|
2805 | * @param $text Performs text search.
|
2806 | * @param $where Matches documents that satisfy a JavaScript expression.
|
2807 | *
|
2808 | * @param $geoIntersects Selects geometries that intersect with a {@link https://docs.mongodb.com/v3.6/reference/glossary/#term-geojson GeoJSON} geometry.
|
2809 | * The {@link https://docs.mongodb.com/v3.6/core/2dsphere/ 2dsphere} index supports {@link https://docs.mongodb.com/v3.6/reference/operator/query/geoIntersects/#op._S_geoIntersects $geoIntersects}.
|
2810 | * @param $geoWithin Selects geometries within a bounding {@link https://docs.mongodb.com/v3.6/reference/geojson/#geospatial-indexes-store-geojson GeoJSON geometry}.
|
2811 | * The {@link https://docs.mongodb.com/v3.6/core/2dsphere/ 2dsphere} and {@link https://docs.mongodb.com/v3.6/core/2d/ 2d} indexes
|
2812 | * support {@link https://docs.mongodb.com/v3.6/reference/operator/query/geoWithin/#op._S_geoWithin $geoWithin}.
|
2813 | * @param $near Returns geospatial objects in proximity to a point. Requires a geospatial index. The {@link https://docs.mongodb.com/v3.6/core/2dsphere/ 2dsphere}
|
2814 | * and {@link https://docs.mongodb.com/v3.6/core/2d/ 2d} indexes support {@link https://docs.mongodb.com/v3.6/reference/operator/query/near/#op._S_near $near}.
|
2815 | * @param $nearSphere Returns geospatial objects in proximity to a point on a sphere. Requires a geospatial index. The {@link https://docs.mongodb.com/v3.6/core/2dsphere/ 2dsphere} and
|
2816 | * {@link https://docs.mongodb.com/v3.6/reference/operator/query/nearSphere/#op._S_nearSphere 2d} indexes support
|
2817 | * {@link https://docs.mongodb.com/v3.6/reference/operator/query/nearSphere/#op._S_nearSphere $nearSphere}.
|
2818 | *
|
2819 | * @param $all Matches arrays that contain all elements specified in the query.
|
2820 | * @param $elemMatch Selects documents if element in the array field matches all the specified
|
2821 | * {@link https://docs.mongodb.com/v3.6/reference/operator/query/elemMatch/#op._S_elemMatch $elemMatch} conditions.
|
2822 | * @param $size Selects documents if the array field is a specified size.
|
2823 | *
|
2824 | * @param $bitsAllClear Matches numeric or binary values in which a set of bit positions all have a value of `0`.
|
2825 | * @param $bitsAllSet Matches numeric or binary values in which a set of bit positions all have a value of `1`.
|
2826 | * @param $bitsAnyClear Matches numeric or binary values in which any bit from a set of bit positions has a value of `0`.
|
2827 | * @param $bitsAnySet Matches numeric or binary values in which any bit from a set of bit positions has a value of `1`.
|
2828 | *
|
2829 | * @see https://docs.mongodb.com/v3.6/reference/operator/query/#query-selectors
|
2830 | */
|
2831 | export type QuerySelector<T> = {
|
2832 | // Comparison
|
2833 | $eq?: T;
|
2834 | $gt?: T;
|
2835 | $gte?: T;
|
2836 | $in?: T[];
|
2837 | $lt?: T;
|
2838 | $lte?: T;
|
2839 | $ne?: T;
|
2840 | $nin?: T[];
|
2841 | // Logical
|
2842 | $not?: T extends string ? QuerySelector<T> | RegExp : QuerySelector<T>;
|
2843 | // Element
|
2844 | /**
|
2845 | * When `true`, `$exists` matches the documents that contain the field,
|
2846 | * including documents where the field value is null.
|
2847 | */
|
2848 | $exists?: boolean;
|
2849 | $type?: BSONType | BSONTypeAlias;
|
2850 | // Evaluation
|
2851 | $expr?: any;
|
2852 | $jsonSchema?: any;
|
2853 | $mod?: T extends number ? [number, number] : never;
|
2854 | $regex?: T extends string ? RegExp | string : never;
|
2855 | $options?: T extends string ? string : never;
|
2856 | // Geospatial
|
2857 | // TODO: define better types for geo queries
|
2858 | $geoIntersects?: { $geometry: object };
|
2859 | $geoWithin?: object;
|
2860 | $near?: object;
|
2861 | $nearSphere?: object;
|
2862 | $maxDistance?: number;
|
2863 | // Array
|
2864 | // TODO: define better types for $all and $elemMatch
|
2865 | $all?: T extends ReadonlyArray<infer U> ? any[] : never;
|
2866 | $elemMatch?: T extends ReadonlyArray<infer U> ? object : never;
|
2867 | $size?: T extends ReadonlyArray<infer U> ? number : never;
|
2868 | // Bitwise
|
2869 | $bitsAllClear?: BitwiseQuery;
|
2870 | $bitsAllSet?: BitwiseQuery;
|
2871 | $bitsAnyClear?: BitwiseQuery;
|
2872 | $bitsAnySet?: BitwiseQuery;
|
2873 | };
|
2874 |
|
2875 | export type RootQuerySelector<T> = {
|
2876 | /** @see https://docs.mongodb.com/v3.6/reference/operator/query/and/#op._S_and */
|
2877 | $and?: Array<FilterQuery<T>>;
|
2878 | /** @see https://docs.mongodb.com/v3.6/reference/operator/query/nor/#op._S_nor */
|
2879 | $nor?: Array<FilterQuery<T>>;
|
2880 | /** @see https://docs.mongodb.com/v3.6/reference/operator/query/or/#op._S_or */
|
2881 | $or?: Array<FilterQuery<T>>;
|
2882 | /** @see https://docs.mongodb.com/v3.6/reference/operator/query/text */
|
2883 | $text?: {
|
2884 | $search: string;
|
2885 | $language?: string;
|
2886 | $caseSensitive?: boolean;
|
2887 | $diacriticSensitive?: boolean;
|
2888 | };
|
2889 | /** @see https://docs.mongodb.com/v3.6/reference/operator/query/where/#op._S_where */
|
2890 | $where?: string | Function;
|
2891 | /** @see https://docs.mongodb.com/v3.6/reference/operator/query/comment/#op._S_comment */
|
2892 | $comment?: string;
|
2893 | // we could not find a proper TypeScript generic to support nested queries e.g. 'user.friends.name'
|
2894 | // this will mark all unrecognized properties as any (including nested queries)
|
2895 | [key: string]: any;
|
2896 | };
|
2897 |
|
2898 | export type ObjectQuerySelector<T> = T extends object ? { [key in keyof T]?: QuerySelector<T[key]> } : QuerySelector<T>;
|
2899 |
|
2900 | export type Condition<T> = MongoAltQuery<T> | QuerySelector<MongoAltQuery<T>>;
|
2901 |
|
2902 | export type FilterQuery<T> = {
|
2903 | [P in keyof T]?: Condition<T[P]>;
|
2904 | } &
|
2905 | RootQuerySelector<T>;
|
2906 |
|
2907 | /** @see https://docs.mongodb.com/v3.6/reference/method/db.collection.bulkWrite/#insertone */
|
2908 | export type BulkWriteInsertOneOperation<TSchema> = {
|
2909 | insertOne: {
|
2910 | document: OptionalId<TSchema>;
|
2911 | };
|
2912 | };
|
2913 |
|
2914 | /**
|
2915 | * Options for the updateOne and updateMany operations
|
2916 | *
|
2917 | * @param arrayFilters Optional. An array of filter documents that determines which array elements to modify for an update operation on an array field.
|
2918 | * @param collaction Optional. Specifies the collation to use for the operation.
|
2919 | * @param filter The selection criteria for the update. The same {@link https://docs.mongodb.com/v3.6/reference/operator/query/#query-selectors query selectors}
|
2920 | * as in the {@link https://docs.mongodb.com/v3.6/reference/method/db.collection.find/#db.collection.find find()} method are available.
|
2921 | * @param update The modifications to apply.
|
2922 | * @param upsert When true, the operation either creates a new document if no documents match the `filter` or updates the document(s) that match the `filter`.
|
2923 | * For more details see {@link https://docs.mongodb.com/v3.6/reference/method/db.collection.update/#upsert-behavior upsert behavior}
|
2924 | * @see https://docs.mongodb.com/v3.6/reference/method/db.collection.bulkWrite/#updateone-and-updatemany
|
2925 | */
|
2926 | export type BulkWriteUpdateOperation<TSchema> = {
|
2927 | arrayFilters?: object[];
|
2928 | collation?: object;
|
2929 | filter: FilterQuery<TSchema>;
|
2930 | update: UpdateQuery<TSchema>;
|
2931 | upsert?: boolean;
|
2932 | };
|
2933 | export type BulkWriteUpdateOneOperation<TSchema> = {
|
2934 | updateOne: BulkWriteUpdateOperation<TSchema>;
|
2935 | };
|
2936 | export type BulkWriteUpdateManyOperation<TSchema> = {
|
2937 | updateMany: BulkWriteUpdateOperation<TSchema>;
|
2938 | };
|
2939 |
|
2940 | /**
|
2941 | * Options for the replaceOne operation
|
2942 | *
|
2943 | * @param collation Optional. Specifies the {@link https://docs.mongodb.com/v3.6/reference/bson-type-comparison-order/#collation collation} to use for the operation.
|
2944 | * @param filter The selection criteria for the update. The same {@link https://docs.mongodb.com/v3.6/reference/operator/query/#query-selectors query selectors}
|
2945 | * as in the {@link https://docs.mongodb.com/v3.6/reference/method/db.collection.find/#db.collection.find find()} method are available.
|
2946 | * @param replacement The replacement document.
|
2947 | * @param upsert When true, replaceOne either inserts the document from the `replacement` parameter if no document matches the `filter`
|
2948 | * or replaces the document that matches the `filter` with the `replacement` document.
|
2949 | * For more details see {@link https://docs.mongodb.com/v3.6/reference/method/db.collection.update/#upsert-behavior upsert behavior}
|
2950 | * @see https://docs.mongodb.com/v3.6/reference/method/db.collection.bulkWrite/#replaceone
|
2951 | */
|
2952 | export type BulkWriteReplaceOneOperation<TSchema> = {
|
2953 | replaceOne: {
|
2954 | collation?: object;
|
2955 | filter: FilterQuery<TSchema>;
|
2956 | replacement: TSchema;
|
2957 | upsert?: boolean;
|
2958 | };
|
2959 | };
|
2960 |
|
2961 | /**
|
2962 | * Options for the deleteOne and deleteMany operations
|
2963 | *
|
2964 | * @param collation Optional. Specifies the collation to use for the operation.
|
2965 | * @param filter Specifies deletion criteria using {@link https://docs.mongodb.com/v3.6/reference/operator/ query operators}.
|
2966 | * @see https://docs.mongodb.com/v3.6/reference/method/db.collection.bulkWrite/#deleteone-and-deletemany
|
2967 | */
|
2968 | export type BulkWriteDeleteOperation<TSchema> = {
|
2969 | collation?: object;
|
2970 | filter: FilterQuery<TSchema>;
|
2971 | };
|
2972 | export type BulkWriteDeleteOneOperation<TSchema> = {
|
2973 | deleteOne: BulkWriteDeleteOperation<TSchema>;
|
2974 | };
|
2975 | export type BulkWriteDeleteManyOperation<TSchema> = {
|
2976 | deleteMany: BulkWriteDeleteOperation<TSchema>;
|
2977 | };
|
2978 |
|
2979 | /**
|
2980 | * Possible operations with the Collection.bulkWrite method
|
2981 | *
|
2982 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#bulkWrite
|
2983 | */
|
2984 | export type BulkWriteOperation<TSchema> =
|
2985 | | BulkWriteInsertOneOperation<TSchema>
|
2986 | | BulkWriteUpdateOneOperation<TSchema>
|
2987 | | BulkWriteUpdateManyOperation<TSchema>
|
2988 | | BulkWriteReplaceOneOperation<TSchema>
|
2989 | | BulkWriteDeleteOneOperation<TSchema>
|
2990 | | BulkWriteDeleteManyOperation<TSchema>;
|
2991 |
|
2992 | /**
|
2993 | * Returned object for the CollStats command in db.runCommand
|
2994 | *
|
2995 | * @see https://docs.mongodb.org/manual/reference/command/collStats/
|
2996 | */
|
2997 | export interface CollStats {
|
2998 | /**
|
2999 | * Namespace.
|
3000 | */
|
3001 | ns: string;
|
3002 | /**
|
3003 | * Number of documents.
|
3004 | */
|
3005 | count: number;
|
3006 | /**
|
3007 | * Collection size in bytes.
|
3008 | */
|
3009 | size: number;
|
3010 | /**
|
3011 | * Average object size in bytes.
|
3012 | */
|
3013 | avgObjSize: number;
|
3014 | /**
|
3015 | * (Pre)allocated space for the collection in bytes.
|
3016 | */
|
3017 | storageSize: number;
|
3018 | /**
|
3019 | * Number of extents (contiguously allocated chunks of datafile space).
|
3020 | */
|
3021 | numExtents: number;
|
3022 | /**
|
3023 | * Number of indexes.
|
3024 | */
|
3025 | nindexes: number;
|
3026 | /**
|
3027 | * Size of the most recently created extent in bytes.
|
3028 | */
|
3029 | lastExtentSize: number;
|
3030 | /**
|
3031 | * Padding can speed up updates if documents grow.
|
3032 | */
|
3033 | paddingFactor: number;
|
3034 | /**
|
3035 | * A number that indicates the user-set flags on the collection. userFlags only appears when using the mmapv1 storage engine.
|
3036 | */
|
3037 | userFlags?: number;
|
3038 | /**
|
3039 | * Total index size in bytes.
|
3040 | */
|
3041 | totalIndexSize: number;
|
3042 | /**
|
3043 | * Size of specific indexes in bytes.
|
3044 | */
|
3045 | indexSizes: {
|
3046 | _id_: number;
|
3047 | [index: string]: number;
|
3048 | };
|
3049 | /**
|
3050 | * `true` if the collection is capped.
|
3051 | */
|
3052 | capped: boolean;
|
3053 | /**
|
3054 | * The maximum number of documents that may be present in a capped collection.
|
3055 | */
|
3056 | max: number;
|
3057 | /**
|
3058 | * The maximum size of a capped collection.
|
3059 | */
|
3060 | maxSize: number;
|
3061 | wiredTiger?: WiredTigerData;
|
3062 | indexDetails?: any;
|
3063 | ok: number;
|
3064 | }
|
3065 |
|
3066 | export interface WiredTigerData {
|
3067 | LSM: {
|
3068 | "bloom filter false positives": number;
|
3069 | "bloom filter hits": number;
|
3070 | "bloom filter misses": number;
|
3071 | "bloom filter pages evicted from cache": number;
|
3072 | "bloom filter pages read into cache": number;
|
3073 | "bloom filters in the LSM tree": number;
|
3074 | "chunks in the LSM tree": number;
|
3075 | "highest merge generation in the LSM tree": number;
|
3076 | "queries that could have benefited from a Bloom filter that did not exist": number;
|
3077 | "sleep for LSM checkpoint throttle": number;
|
3078 | "sleep for LSM merge throttle": number;
|
3079 | "total size of bloom filters": number;
|
3080 | };
|
3081 | "block-manager": {
|
3082 | "allocations requiring file extension": number;
|
3083 | "blocks allocated": number;
|
3084 | "blocks freed": number;
|
3085 | "checkpoint size": number;
|
3086 | "file allocation unit size": number;
|
3087 | "file bytes available for reuse": number;
|
3088 | "file magic number": number;
|
3089 | "file major version number": number;
|
3090 | "file size in bytes": number;
|
3091 | "minor version number": number;
|
3092 | };
|
3093 | btree: {
|
3094 | "btree checkpoint generation": number;
|
3095 | "column-store fixed-size leaf pages": number;
|
3096 | "column-store internal pages": number;
|
3097 | "column-store variable-size RLE encoded values": number;
|
3098 | "column-store variable-size deleted values": number;
|
3099 | "column-store variable-size leaf pages": number;
|
3100 | "fixed-record size": number;
|
3101 | "maximum internal page key size": number;
|
3102 | "maximum internal page size": number;
|
3103 | "maximum leaf page key size": number;
|
3104 | "maximum leaf page size": number;
|
3105 | "maximum leaf page value size": number;
|
3106 | "maximum tree depth": number;
|
3107 | "number of key/value pairs": number;
|
3108 | "overflow pages": number;
|
3109 | "pages rewritten by compaction": number;
|
3110 | "row-store internal pages": number;
|
3111 | "row-store leaf pages": number;
|
3112 | };
|
3113 | cache: {
|
3114 | "bytes currently in the cache": number;
|
3115 | "bytes read into cache": number;
|
3116 | "bytes written from cache": number;
|
3117 | "checkpoint blocked page eviction": number;
|
3118 | "data source pages selected for eviction unable to be evicted": number;
|
3119 | "hazard pointer blocked page eviction": number;
|
3120 | "in-memory page passed criteria to be split": number;
|
3121 | "in-memory page splits": number;
|
3122 | "internal pages evicted": number;
|
3123 | "internal pages split during eviction": number;
|
3124 | "leaf pages split during eviction": number;
|
3125 | "modified pages evicted": number;
|
3126 | "overflow pages read into cache": number;
|
3127 | "overflow values cached in memory": number;
|
3128 | "page split during eviction deepened the tree": number;
|
3129 | "page written requiring lookaside records": number;
|
3130 | "pages read into cache": number;
|
3131 | "pages read into cache requiring lookaside entries": number;
|
3132 | "pages requested from the cache": number;
|
3133 | "pages written from cache": number;
|
3134 | "pages written requiring in-memory restoration": number;
|
3135 | "tracked dirty bytes in the cache": number;
|
3136 | "unmodified pages evicted": number;
|
3137 | };
|
3138 | cache_walk: {
|
3139 | "Average difference between current eviction generation when the page was last considered": number;
|
3140 | "Average on-disk page image size seen": number;
|
3141 | "Clean pages currently in cache": number;
|
3142 | "Current eviction generation": number;
|
3143 | "Dirty pages currently in cache": number;
|
3144 | "Entries in the root page": number;
|
3145 | "Internal pages currently in cache": number;
|
3146 | "Leaf pages currently in cache": number;
|
3147 | "Maximum difference between current eviction generation when the page was last considered": number;
|
3148 | "Maximum page size seen": number;
|
3149 | "Minimum on-disk page image size seen": number;
|
3150 | "On-disk page image sizes smaller than a single allocation unit": number;
|
3151 | "Pages created in memory and never written": number;
|
3152 | "Pages currently queued for eviction": number;
|
3153 | "Pages that could not be queued for eviction": number;
|
3154 | "Refs skipped during cache traversal": number;
|
3155 | "Size of the root page": number;
|
3156 | "Total number of pages currently in cache": number;
|
3157 | };
|
3158 | compression: {
|
3159 | "compressed pages read": number;
|
3160 | "compressed pages written": number;
|
3161 | "page written failed to compress": number;
|
3162 | "page written was too small to compress": number;
|
3163 | "raw compression call failed, additional data available": number;
|
3164 | "raw compression call failed, no additional data available": number;
|
3165 | "raw compression call succeeded": number;
|
3166 | };
|
3167 | cursor: {
|
3168 | "bulk-loaded cursor-insert calls": number;
|
3169 | "create calls": number;
|
3170 | "cursor-insert key and value bytes inserted": number;
|
3171 | "cursor-remove key bytes removed": number;
|
3172 | "cursor-update value bytes updated": number;
|
3173 | "insert calls": number;
|
3174 | "next calls": number;
|
3175 | "prev calls": number;
|
3176 | "remove calls": number;
|
3177 | "reset calls": number;
|
3178 | "restarted searches": number;
|
3179 | "search calls": number;
|
3180 | "search near calls": number;
|
3181 | "truncate calls": number;
|
3182 | "update calls": number;
|
3183 | };
|
3184 | reconciliation: {
|
3185 | "dictionary matches": number;
|
3186 | "fast-path pages deleted": number;
|
3187 | "internal page key bytes discarded using suffix compression": number;
|
3188 | "internal page multi-block writes": number;
|
3189 | "internal-page overflow keys": number;
|
3190 | "leaf page key bytes discarded using prefix compression": number;
|
3191 | "leaf page multi-block writes": number;
|
3192 | "leaf-page overflow keys": number;
|
3193 | "maximum blocks required for a page": number;
|
3194 | "overflow values written": number;
|
3195 | "page checksum matches": number;
|
3196 | "page reconciliation calls": number;
|
3197 | "page reconciliation calls for eviction": number;
|
3198 | "pages deleted": number;
|
3199 | };
|
3200 | }
|
3201 |
|
3202 | /**
|
3203 | * Options for Collection.aggregate
|
3204 | *
|
3205 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#aggregate
|
3206 | */
|
3207 | export interface CollectionAggregationOptions {
|
3208 | /**
|
3209 | * The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
|
3210 | */
|
3211 | readPreference?: ReadPreferenceOrMode;
|
3212 | /**
|
3213 | * Return the query as cursor, on 2.6 > it returns as a real cursor
|
3214 | * on pre 2.6 it returns as an emulated cursor.
|
3215 | */
|
3216 | cursor?: { batchSize?: number };
|
3217 | /**
|
3218 | * Explain returns the aggregation execution plan (requires mongodb 2.6 >).
|
3219 | */
|
3220 | explain?: boolean;
|
3221 | /**
|
3222 | * Lets the server know if it can use disk to store
|
3223 | * temporary results for the aggregation (requires mongodb 2.6 >).
|
3224 | */
|
3225 | allowDiskUse?: boolean;
|
3226 | /**
|
3227 | * specifies a cumulative time limit in milliseconds for processing operations
|
3228 | * on the cursor. MongoDB interrupts the operation at the earliest following interrupt point.
|
3229 | */
|
3230 | maxTimeMS?: number;
|
3231 | /**
|
3232 | * Allow driver to bypass schema validation in MongoDB 3.2 or higher.
|
3233 | */
|
3234 | bypassDocumentValidation?: boolean;
|
3235 | hint?: string | object;
|
3236 | raw?: boolean;
|
3237 | promoteLongs?: boolean;
|
3238 | promoteValues?: boolean;
|
3239 | promoteBuffers?: boolean;
|
3240 | collation?: CollationDocument;
|
3241 | comment?: string;
|
3242 | session?: ClientSession;
|
3243 | }
|
3244 |
|
3245 | /**
|
3246 | * Options for Collection.insertMany
|
3247 | *
|
3248 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#insertMany
|
3249 | */
|
3250 | export interface CollectionInsertManyOptions extends CommonOptions {
|
3251 | /**
|
3252 | * Serialize functions on any object.
|
3253 | */
|
3254 | serializeFunctions?: boolean;
|
3255 | /**
|
3256 | * Force server to assign _id values instead of driver.
|
3257 | */
|
3258 | forceServerObjectId?: boolean;
|
3259 | /**
|
3260 | * Allow driver to bypass schema validation in MongoDB 3.2 or higher.
|
3261 | */
|
3262 | bypassDocumentValidation?: boolean;
|
3263 | /**
|
3264 | * If true, when an insert fails, don't execute the remaining writes. If false, continue with remaining inserts when one fails.
|
3265 | */
|
3266 | ordered?: boolean;
|
3267 | }
|
3268 |
|
3269 | /**
|
3270 | * Options for Collection.bulkWrite
|
3271 | *
|
3272 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#bulkWrite
|
3273 | */
|
3274 | export interface CollectionBulkWriteOptions extends CommonOptions {
|
3275 | /**
|
3276 | * Serialize functions on any object.
|
3277 | */
|
3278 | serializeFunctions?: boolean;
|
3279 | /**
|
3280 | * Execute write operation in ordered or unordered fashion.
|
3281 | */
|
3282 | ordered?: boolean;
|
3283 | /**
|
3284 | * Allow driver to bypass schema validation in MongoDB 3.2 or higher.
|
3285 | */
|
3286 | bypassDocumentValidation?: boolean;
|
3287 | //Force server to assign _id values instead of driver.
|
3288 | forceServerObjectId?: boolean;
|
3289 | }
|
3290 |
|
3291 | /**
|
3292 | * Returning object for Collection.bulkWrite operations
|
3293 | *
|
3294 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#~BulkWriteOpResult
|
3295 | */
|
3296 | export interface BulkWriteOpResultObject {
|
3297 | insertedCount?: number;
|
3298 | matchedCount?: number;
|
3299 | modifiedCount?: number;
|
3300 | deletedCount?: number;
|
3301 | upsertedCount?: number;
|
3302 | insertedIds?: { [index: number]: any };
|
3303 | upsertedIds?: { [index: number]: any };
|
3304 | result?: any;
|
3305 | }
|
3306 |
|
3307 | /**
|
3308 | * Options for Collection.count
|
3309 | *
|
3310 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#count
|
3311 | */
|
3312 | export interface MongoCountPreferences {
|
3313 | /**
|
3314 | * The limit of documents to count.
|
3315 | */
|
3316 | limit?: number;
|
3317 | /**
|
3318 | * The number of documents to skip for the count.
|
3319 | */
|
3320 | skip?: number;
|
3321 | /**
|
3322 | * An index name hint for the query.
|
3323 | */
|
3324 | hint?: string;
|
3325 | /**
|
3326 | * The preferred read preference
|
3327 | */
|
3328 | readPreference?: ReadPreferenceOrMode;
|
3329 | /**
|
3330 | * Number of miliseconds to wait before aborting the query.
|
3331 | */
|
3332 | maxTimeMS?: number;
|
3333 | /**
|
3334 | * Optional session to use for this operation
|
3335 | */
|
3336 | session?: ClientSession;
|
3337 | }
|
3338 |
|
3339 | /**
|
3340 | * Options for Collection.distinct
|
3341 | *
|
3342 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#distinct
|
3343 | */
|
3344 | export interface MongoDistinctPreferences {
|
3345 | /**
|
3346 | * The preferred read preference
|
3347 | */
|
3348 | readPreference?: ReadPreferenceOrMode;
|
3349 | /**
|
3350 | * Number of miliseconds to wait before aborting the query.
|
3351 | */
|
3352 | maxTimeMS?: number;
|
3353 | /**
|
3354 | * Optional session to use for this operation
|
3355 | */
|
3356 | session?: ClientSession;
|
3357 | }
|
3358 |
|
3359 | /**
|
3360 | * Returning object from delete write operations
|
3361 | *
|
3362 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#~deleteWriteOpResult
|
3363 | */
|
3364 | export interface DeleteWriteOpResultObject {
|
3365 | //The raw result returned from MongoDB, field will vary depending on server version.
|
3366 | result: {
|
3367 | //Is 1 if the command executed correctly.
|
3368 | ok?: number;
|
3369 | //The total count of documents deleted.
|
3370 | n?: number;
|
3371 | };
|
3372 | //The connection object used for the operation.
|
3373 | connection?: any;
|
3374 | //The number of documents deleted.
|
3375 | deletedCount?: number;
|
3376 | }
|
3377 |
|
3378 | /**
|
3379 | * Returning object from findAndModify operations
|
3380 | *
|
3381 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#~findAndModifyWriteOpResult
|
3382 | */
|
3383 | export interface FindAndModifyWriteOpResultObject<TSchema> {
|
3384 | //Document returned from findAndModify command.
|
3385 | value?: TSchema;
|
3386 | //The raw lastErrorObject returned from the command.
|
3387 | lastErrorObject?: any;
|
3388 | //Is 1 if the command executed correctly.
|
3389 | ok?: number;
|
3390 | }
|
3391 |
|
3392 | /**
|
3393 | * Returning object from findAndReplace operations
|
3394 | *
|
3395 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#findOneAndReplace
|
3396 | */
|
3397 | export interface FindOneAndReplaceOption<T> extends CommonOptions {
|
3398 | projection?: SchemaMember<T, ProjectionOperators | number | boolean | any>;
|
3399 | sort?: SortOptionObject<T>;
|
3400 | maxTimeMS?: number;
|
3401 | upsert?: boolean;
|
3402 | returnDocument?: 'after' | 'before';
|
3403 | /** @deprecated Use returnDocument */
|
3404 | returnOriginal?: boolean;
|
3405 | collation?: CollationDocument;
|
3406 | }
|
3407 |
|
3408 | /**
|
3409 | * Possible projection operators
|
3410 | *
|
3411 | * @see https://docs.mongodb.com/v3.6/reference/operator/projection/
|
3412 | */
|
3413 | export interface ProjectionOperators {
|
3414 | /** @see https://docs.mongodb.com/v3.6/reference/operator/projection/elemMatch/#proj._S_elemMatch */
|
3415 | $elemMatch?: object;
|
3416 | /** @see https://docs.mongodb.com/v3.6/reference/operator/projection/slice/#proj._S_slice */
|
3417 | $slice?: number | [number, number];
|
3418 | $meta?: MetaProjectionOperators;
|
3419 | }
|
3420 |
|
3421 | /**
|
3422 | * Returning object from findOneAndUpdate operations
|
3423 | *
|
3424 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#findOneAndUpdate
|
3425 | */
|
3426 | export interface FindOneAndUpdateOption<T> extends FindOneAndReplaceOption<T> {
|
3427 | arrayFilters?: object[];
|
3428 | }
|
3429 |
|
3430 | /**
|
3431 | * Returning object from findOneAndDelete operations
|
3432 | *
|
3433 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#findOneAndDelete
|
3434 | */
|
3435 | export interface FindOneAndDeleteOption<T> {
|
3436 | projection?: SchemaMember<T, ProjectionOperators | number | boolean | any>;
|
3437 | sort?: SortOptionObject<T>;
|
3438 | maxTimeMS?: number;
|
3439 | session?: ClientSession;
|
3440 | collation?: CollationDocument;
|
3441 | }
|
3442 |
|
3443 | /**
|
3444 | * Options for Collection.geoHaystackSearch
|
3445 | *
|
3446 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#geoHaystackSearch
|
3447 | */
|
3448 | export interface GeoHaystackSearchOptions {
|
3449 | readPreference?: ReadPreferenceOrMode;
|
3450 | maxDistance?: number;
|
3451 | search?: object;
|
3452 | limit?: number;
|
3453 | session?: ClientSession;
|
3454 | }
|
3455 |
|
3456 | /**
|
3457 | * A class representation of the BSON Code type.
|
3458 | *
|
3459 | * @param name a string or function.
|
3460 | * @param scope an optional scope for the function.
|
3461 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Code.html
|
3462 | */
|
3463 | export class Code {
|
3464 | constructor(code: string | Function, scope?: object);
|
3465 | code: string | Function;
|
3466 | scope: any;
|
3467 | }
|
3468 |
|
3469 | /**
|
3470 | * Create a new OrderedBulkOperation instance (INTERNAL TYPE, do not instantiate directly)
|
3471 | *
|
3472 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/OrderedBulkOperation.html
|
3473 | */
|
3474 | export interface OrderedBulkOperation {
|
3475 | length: number;
|
3476 | /**
|
3477 | * Execute the bulk operation
|
3478 | *
|
3479 | * @param _writeConcern Optional write concern. Can also be specified through options
|
3480 | * @param options Optional settings
|
3481 | * @param callback A callback that will be invoked when bulkWrite finishes/errors
|
3482 | * @returns Promise if no callback is passed
|
3483 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/OrderedBulkOperation.html#execute
|
3484 | */
|
3485 | execute(callback: MongoCallback<BulkWriteResult>): void;
|
3486 | execute(options?: FSyncOptions): Promise<BulkWriteResult>;
|
3487 | execute(options: FSyncOptions, callback: MongoCallback<BulkWriteResult>): void;
|
3488 | /**
|
3489 | * Builds a find operation for an update/updateOne/delete/deleteOne/replaceOne.
|
3490 | * Returns a builder object used to complete the definition of the operation.
|
3491 | *
|
3492 | * @param selector The selector for the bulk operation. See {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-q q documentation}
|
3493 | * @returns helper object with which the write operation can be defined.
|
3494 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/OrderedBulkOperation.html#find
|
3495 | */
|
3496 | find(selector: object): FindOperators;
|
3497 | /**
|
3498 | * Add a single insert document to the bulk operation
|
3499 | *
|
3500 | * @param document the document to insert
|
3501 | * @returns reference to self
|
3502 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/OrderedBulkOperation.html#insert
|
3503 | */
|
3504 | insert(document: object): OrderedBulkOperation;
|
3505 | }
|
3506 |
|
3507 | /**
|
3508 | * Returning upserted object from bulkWrite operations
|
3509 | *
|
3510 | * @see https://docs.mongodb.com/v3.6/reference/method/BulkWriteResult/index.html#BulkWriteResult.upserted
|
3511 | */
|
3512 | export interface BulkWriteResultUpsertedIdObject {
|
3513 | index: number;
|
3514 | _id: ObjectId;
|
3515 | }
|
3516 |
|
3517 | /**
|
3518 | * Returning object from bulkWrite operations
|
3519 | *
|
3520 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/BulkWriteResult.html
|
3521 | */
|
3522 | export interface BulkWriteResult {
|
3523 | /**
|
3524 | * Evaluates to `true` if the bulk operation correctly executes
|
3525 | */
|
3526 | ok: boolean;
|
3527 |
|
3528 | /**
|
3529 | * The number of documents inserted, excluding upserted documents.
|
3530 | */
|
3531 | nInserted: number;
|
3532 |
|
3533 | /**
|
3534 | * The number of documents selected for update.
|
3535 | *
|
3536 | * If the update operation results in no change to the document,
|
3537 | * e.g. `$set` expression updates the value to the current value,
|
3538 | * nMatched can be greater than nModified.
|
3539 | */
|
3540 | nMatched: number;
|
3541 |
|
3542 | /**
|
3543 | * The number of existing documents updated.
|
3544 | *
|
3545 | * If the update/replacement operation results in no change to the document,
|
3546 | * such as setting the value of the field to its current value,
|
3547 | * nModified can be less than nMatched
|
3548 | */
|
3549 | nModified: number;
|
3550 |
|
3551 | /**
|
3552 | * The number of documents inserted by an {@link https://docs.mongodb.com/v3.6/reference/method/db.collection.update/#upsert-parameter upsert}.
|
3553 | */
|
3554 | nUpserted: number;
|
3555 |
|
3556 | /**
|
3557 | * The number of documents removed.
|
3558 | */
|
3559 | nRemoved: number;
|
3560 |
|
3561 | /**
|
3562 | * Returns an array of all inserted ids
|
3563 | */
|
3564 | getInsertedIds(): object[];
|
3565 | /**
|
3566 | * Retrieve lastOp if available
|
3567 | */
|
3568 | getLastOp(): object;
|
3569 | /**
|
3570 | * Returns raw internal result
|
3571 | */
|
3572 | getRawResponse(): object;
|
3573 |
|
3574 | /**
|
3575 | * Returns the upserted id at the given index
|
3576 | *
|
3577 | * @param index the number of the upserted id to return, returns `undefined` if no result for passed in index
|
3578 | */
|
3579 | getUpsertedIdAt(index: number): BulkWriteResultUpsertedIdObject;
|
3580 |
|
3581 | /**
|
3582 | * Returns an array of all upserted ids
|
3583 | */
|
3584 | getUpsertedIds(): BulkWriteResultUpsertedIdObject[];
|
3585 | /**
|
3586 | * Retrieve the write concern error if any
|
3587 | */
|
3588 | getWriteConcernError(): WriteConcernError;
|
3589 |
|
3590 | /**
|
3591 | * Returns a specific write error object
|
3592 | *
|
3593 | * @param index of the write error to return, returns `null` if there is no result for passed in index
|
3594 | */
|
3595 | getWriteErrorAt(index: number): WriteError;
|
3596 |
|
3597 | /**
|
3598 | * Returns the number of write errors off the bulk operation
|
3599 | */
|
3600 | getWriteErrorCount(): number;
|
3601 | /**
|
3602 | * Retrieve all write errors
|
3603 | */
|
3604 | getWriteErrors(): object[];
|
3605 | /**
|
3606 | * Returns `true` if the bulk operation contains a write error
|
3607 | */
|
3608 | hasWriteErrors(): boolean;
|
3609 | }
|
3610 |
|
3611 | /**
|
3612 | * An error that occurred during a BulkWrite on the server.
|
3613 | *
|
3614 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/WriteError.html
|
3615 | */
|
3616 | export interface WriteError {
|
3617 | /**
|
3618 | * Write concern error code.
|
3619 | */
|
3620 | code: number;
|
3621 | /**
|
3622 | * Write concern error original bulk operation index.
|
3623 | */
|
3624 | index: number;
|
3625 | /**
|
3626 | * Write concern error message.
|
3627 | */
|
3628 | errmsg: string;
|
3629 | }
|
3630 |
|
3631 | /**
|
3632 | * An error representing a failure by the server to apply the requested write concern to the bulk operation.
|
3633 | *
|
3634 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/WriteConcernError.html
|
3635 | */
|
3636 | export interface WriteConcernError {
|
3637 | /**
|
3638 | * Write concern error code.
|
3639 | */
|
3640 | code: number;
|
3641 | /**
|
3642 | * Write concern error message.
|
3643 | */
|
3644 | errmsg: string;
|
3645 | }
|
3646 |
|
3647 | /**
|
3648 | * A builder object that is returned from {@link https://mongodb.github.io/node-mongodb-native/3.6/api/BulkOperationBase.html#find BulkOperationBase#find}.
|
3649 | * Is used to build a write operation that involves a query filter.
|
3650 | *
|
3651 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/FindOperators.html
|
3652 | */
|
3653 | export interface FindOperators {
|
3654 | /**
|
3655 | * Add a delete many operation to the bulk operation
|
3656 | *
|
3657 | * @returns reference to the parent BulkOperation
|
3658 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/FindOperators.html#delete
|
3659 | */
|
3660 | delete(): OrderedBulkOperation;
|
3661 | /**
|
3662 | * Add a delete one operation to the bulk operation
|
3663 | *
|
3664 | * @returns reference to the parent BulkOperation
|
3665 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/FindOperators.html#deleteOne
|
3666 | */
|
3667 | deleteOne(): OrderedBulkOperation;
|
3668 | /**
|
3669 | * Backwards compatibility for {@link https://mongodb.github.io/node-mongodb-native/3.6/api/FindOperators.html#delete delete()}
|
3670 | * @deprecated As of version 3.6.7
|
3671 | *
|
3672 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/FindOperators.html#remove
|
3673 | */
|
3674 | remove(): OrderedBulkOperation;
|
3675 | /**
|
3676 | * Backwards compatibility for {@link https://mongodb.github.io/node-mongodb-native/3.6/api/FindOperators.html#deleteOne deleteOne()}
|
3677 | * @deprecated As of version 3.6.7
|
3678 | *
|
3679 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/FindOperators.html#removeOne
|
3680 | */
|
3681 | removeOne(): OrderedBulkOperation;
|
3682 | /**
|
3683 | * Add a replace one operation to the bulk operation
|
3684 | *
|
3685 | * @param replacement the new document to replace the existing one with
|
3686 | * @returns reference to the parent BulkOperation
|
3687 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/FindOperators.html#replaceOne
|
3688 | */
|
3689 | replaceOne(replacement: object): OrderedBulkOperation;
|
3690 | /**
|
3691 | * Add a multiple update operation to the bulk operation
|
3692 | *
|
3693 | * @param updateDocument An update field for an update operation. See {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-u u documentation}
|
3694 | * @param options Optional settings
|
3695 | * @returns reference to the parent BulkOperation
|
3696 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/FindOperators.html#update
|
3697 | */
|
3698 | update(updateDocument: object, options?: { hint: object }): OrderedBulkOperation;
|
3699 | /**
|
3700 | * Add a single update operation to the bulk operation
|
3701 | *
|
3702 | * @param updateDocument An update field for an update operation. See {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-u u documentation}
|
3703 | * @param options Optional settings
|
3704 | * @returns reference to the parent BulkOperation
|
3705 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/FindOperators.html#updateOne
|
3706 | */
|
3707 | updateOne(updateDocument: object, options?: { hint: object }): OrderedBulkOperation;
|
3708 | /**
|
3709 | * Upsert modifier for update bulk operation, noting that this operation is an upsert.
|
3710 | *
|
3711 | * @returns reference to self
|
3712 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/FindOperators.html#upsert
|
3713 | */
|
3714 | upsert(): FindOperators;
|
3715 | }
|
3716 |
|
3717 | /**
|
3718 | * Create a new UnorderedBulkOperation instance (INTERNAL TYPE, do not instantiate directly)
|
3719 | *
|
3720 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/UnorderedBulkOperation.html
|
3721 | */
|
3722 | export interface UnorderedBulkOperation {
|
3723 | /**
|
3724 | * Get the number of operations in the bulk.
|
3725 | */
|
3726 | length: number;
|
3727 | /**
|
3728 | * Execute the bulk operation
|
3729 | *
|
3730 | * @param _writeConcern Optional write concern. Can also be specified through options.
|
3731 | * @param options Optional settings
|
3732 | * @param callback A callback that will be invoked when bulkWrite finishes/errors
|
3733 | * @returns Promise if no callback is passed
|
3734 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/UnorderedBulkOperation.html#execute
|
3735 | */
|
3736 | execute(callback: MongoCallback<BulkWriteResult>): void;
|
3737 | execute(options?: FSyncOptions): Promise<BulkWriteResult>;
|
3738 | execute(options: FSyncOptions, callback: MongoCallback<BulkWriteResult>): void;
|
3739 | /**
|
3740 | * Builds a find operation for an update/updateOne/delete/deleteOne/replaceOne.
|
3741 | * Returns a builder object used to complete the definition of the operation.
|
3742 | *
|
3743 | * @param selector The selector for the bulk operation. See {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-q q documentation}
|
3744 | * @returns helper object with which the write operation can be defined.
|
3745 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/UnorderedBulkOperation.html#find
|
3746 | */
|
3747 | find(selector: object): FindOperators;
|
3748 | /**
|
3749 | * Add a single insert document to the bulk operation
|
3750 | *
|
3751 | * @param document the document to insert
|
3752 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/UnorderedBulkOperation.html#insert
|
3753 | */
|
3754 | insert(document: object): UnorderedBulkOperation;
|
3755 | }
|
3756 |
|
3757 | /**
|
3758 | * Options for Collection.findOne operations
|
3759 | *
|
3760 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#findOne
|
3761 | */
|
3762 | export interface FindOneOptions<T> {
|
3763 | limit?: number;
|
3764 | sort?: Array<[string, number]> | SortOptionObject<T>;
|
3765 | projection?: SchemaMember<T, ProjectionOperators | number | boolean | any>;
|
3766 | /**
|
3767 | * @deprecated Use options.projection instead
|
3768 | */
|
3769 | fields?: { [P in keyof T]: boolean | number };
|
3770 | skip?: number;
|
3771 | hint?: object;
|
3772 | explain?: boolean;
|
3773 | snapshot?: boolean;
|
3774 | timeout?: boolean;
|
3775 | tailable?: boolean;
|
3776 | awaitData?: boolean;
|
3777 | batchSize?: number;
|
3778 | returnKey?: boolean;
|
3779 | maxScan?: number;
|
3780 | min?: number;
|
3781 | max?: number;
|
3782 | showDiskLoc?: boolean;
|
3783 | comment?: string;
|
3784 | raw?: boolean;
|
3785 | promoteLongs?: boolean;
|
3786 | promoteValues?: boolean;
|
3787 | promoteBuffers?: boolean;
|
3788 | readPreference?: ReadPreferenceOrMode;
|
3789 | partial?: boolean;
|
3790 | maxTimeMS?: number;
|
3791 | collation?: CollationDocument;
|
3792 | session?: ClientSession;
|
3793 | }
|
3794 |
|
3795 | /**
|
3796 | * Options for Collection.insertOne operations
|
3797 | *
|
3798 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#insertOne
|
3799 | */
|
3800 | export interface CollectionInsertOneOptions extends CommonOptions {
|
3801 | /**
|
3802 | * Serialize functions on any object.
|
3803 | */
|
3804 | serializeFunctions?: boolean;
|
3805 | /**
|
3806 | * Force server to assign _id values instead of driver.
|
3807 | */
|
3808 | forceServerObjectId?: boolean;
|
3809 | /**
|
3810 | * Allow driver to bypass schema validation in MongoDB 3.2 or higher.
|
3811 | */
|
3812 | bypassDocumentValidation?: boolean;
|
3813 | }
|
3814 |
|
3815 | /**
|
3816 | * Returning object from insert write operations
|
3817 | *
|
3818 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#~insertWriteOpResult
|
3819 | */
|
3820 | export interface InsertWriteOpResult<TSchema extends { _id: any }> {
|
3821 | insertedCount: number;
|
3822 | ops: TSchema[];
|
3823 | insertedIds: { [key: number]: TSchema["_id"] };
|
3824 | connection: any;
|
3825 | result: { ok: number; n: number };
|
3826 | }
|
3827 |
|
3828 | /**
|
3829 | * Returning object from insertOne write operations
|
3830 | *
|
3831 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#~insertOneWriteOpResult
|
3832 | */
|
3833 | export interface InsertOneWriteOpResult<TSchema extends { _id: any }> {
|
3834 | insertedCount: number;
|
3835 | ops: TSchema[];
|
3836 | insertedId: TSchema["_id"];
|
3837 | connection: any;
|
3838 | result: { ok: number; n: number };
|
3839 | }
|
3840 |
|
3841 | /**
|
3842 | * Options for Collection.parallelCollectionScan operations
|
3843 | *
|
3844 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#parallelCollectionScan
|
3845 | */
|
3846 | export interface ParallelCollectionScanOptions {
|
3847 | readPreference?: ReadPreferenceOrMode;
|
3848 | batchSize?: number;
|
3849 | numCursors?: number;
|
3850 | raw?: boolean;
|
3851 | session?: ClientSession;
|
3852 | }
|
3853 |
|
3854 | /**
|
3855 | * Options for Collection.replaceOne operations
|
3856 | *
|
3857 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#replaceOne
|
3858 | */
|
3859 | export interface ReplaceOneOptions extends CommonOptions {
|
3860 | upsert?: boolean;
|
3861 | bypassDocumentValidation?: boolean;
|
3862 | }
|
3863 |
|
3864 | /**
|
3865 | * Options for Collection.updateOne operations
|
3866 | *
|
3867 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#updateOne
|
3868 | */
|
3869 | export interface UpdateOneOptions extends ReplaceOneOptions {
|
3870 | arrayFilters?: object[];
|
3871 | }
|
3872 |
|
3873 | /**
|
3874 | * Options for Collection.updateMany operations
|
3875 | *
|
3876 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#updateMany
|
3877 | */
|
3878 | export interface UpdateManyOptions extends CommonOptions {
|
3879 | upsert?: boolean;
|
3880 | arrayFilters?: object[];
|
3881 | }
|
3882 |
|
3883 | /**
|
3884 | * Returning object from update write operations
|
3885 | *
|
3886 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#~updateWriteOpResult
|
3887 | */
|
3888 | export interface UpdateWriteOpResult {
|
3889 | result: { ok: number; n: number; nModified: number };
|
3890 | connection: any;
|
3891 | matchedCount: number;
|
3892 | modifiedCount: number;
|
3893 | upsertedCount: number;
|
3894 | upsertedId: { _id: ObjectId };
|
3895 | }
|
3896 |
|
3897 | /**
|
3898 | * Returning object from replace write operations
|
3899 | *
|
3900 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#~updateWriteOpResult
|
3901 | */
|
3902 | export interface ReplaceWriteOpResult extends UpdateWriteOpResult {
|
3903 | ops: any[];
|
3904 | }
|
3905 |
|
3906 | /**
|
3907 | * Options for Collection.mapReduce operations
|
3908 | *
|
3909 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#mapReduce
|
3910 | */
|
3911 | export interface MapReduceOptions {
|
3912 | readPreference?: ReadPreferenceOrMode;
|
3913 | out?: object;
|
3914 | query?: object;
|
3915 | sort?: object;
|
3916 | limit?: number;
|
3917 | keeptemp?: boolean;
|
3918 | finalize?: Function | string;
|
3919 | scope?: object;
|
3920 | jsMode?: boolean;
|
3921 | verbose?: boolean;
|
3922 | bypassDocumentValidation?: boolean;
|
3923 | session?: ClientSession;
|
3924 | }
|
3925 |
|
3926 | export type CollectionMapFunction<TSchema> = (this: TSchema) => void;
|
3927 |
|
3928 | export type CollectionReduceFunction<TKey, TValue> = (key: TKey, values: TValue[]) => TValue;
|
3929 |
|
3930 | /**
|
3931 | * Returning object from write operations
|
3932 | *
|
3933 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#~WriteOpResult
|
3934 | */
|
3935 | export interface WriteOpResult {
|
3936 | ops: any[];
|
3937 | connection: any;
|
3938 | result: any;
|
3939 | }
|
3940 |
|
3941 | /**
|
3942 | * Callback for cursor operations
|
3943 | *
|
3944 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#~resultCallback
|
3945 | */
|
3946 | export type CursorResult = object | null | boolean;
|
3947 |
|
3948 | type Default = any;
|
3949 | type DefaultSchema = any;
|
3950 |
|
3951 | /**
|
3952 | * Creates a new Cursor instance (INTERNAL TYPE, do not instantiate directly)
|
3953 | *
|
3954 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html
|
3955 | */
|
3956 | export class Cursor<T = Default> extends Readable {
|
3957 | [Symbol.asyncIterator](): AsyncIterableIterator<T>;
|
3958 | sortValue: string;
|
3959 | timeout: boolean;
|
3960 | readPreference: ReadPreference;
|
3961 | /**
|
3962 | * Add a cursor flag to the cursor
|
3963 | *
|
3964 | * @param flag The flag to set, must be one of following ['`tailable`', '`oplogReplay`', '`noCursorTimeout`', '`awaitData`', '`partial`'].
|
3965 | * @param value The flag boolean value.
|
3966 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#addCursorFlag
|
3967 | */
|
3968 | addCursorFlag(flag: 'tailable' | 'oplogReplay' | 'noCursorTimeout' | 'awaitData' | 'partial' | string, value: boolean): Cursor<T>;
|
3969 | /**
|
3970 | * Add a query modifier to the cursor query
|
3971 | *
|
3972 | * @param name The query modifier (must start with $, such as `$orderby` etc)
|
3973 | * @param value The modifier value.
|
3974 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#addQueryModifier
|
3975 | */
|
3976 | addQueryModifier(name: string, value: boolean | string | number): Cursor<T>;
|
3977 | /**
|
3978 | * Set the batch size for the cursor.
|
3979 | * The number of documents to return per batch. See {@link https://docs.mongodb.com/manual/reference/command/find/ find command documentation}.
|
3980 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#batchSize
|
3981 | */
|
3982 | batchSize(value: number): Cursor<T>;
|
3983 | /**
|
3984 | * Clone the cursor
|
3985 | *
|
3986 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#clone
|
3987 | */
|
3988 | clone(): Cursor<T>; // still returns the same type
|
3989 | /**
|
3990 | * Close the cursor, sending a KillCursor command and emitting close.
|
3991 | *
|
3992 | * @param options Optional settings
|
3993 | * @param callback The result callback
|
3994 | * @returns Promise if no callback is passed
|
3995 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#close
|
3996 | */
|
3997 | close(options?: { skipKillCursors: boolean }): Promise<CursorResult>;
|
3998 | close(options: { skipKillCursors: boolean }, callback: MongoCallback<CursorResult>): void;
|
3999 | close(callback: MongoCallback<CursorResult>): void;
|
4000 | /**
|
4001 | * Set the collation options for the cursor.
|
4002 | *
|
4003 | * @param value The cursor collation options (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
|
4004 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#collation
|
4005 | */
|
4006 | collation(value: CollationDocument): Cursor<T>;
|
4007 | /**
|
4008 | * Add a comment to the cursor query allowing for tracking the comment in the log.
|
4009 | *
|
4010 | * @param value The comment attached to this query.
|
4011 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#comment
|
4012 | */
|
4013 | comment(value: string): Cursor<T>;
|
4014 | /**
|
4015 | * Get the count of documents for this cursor
|
4016 | *
|
4017 | * @param applySkipLimit Should the count command apply limit and skip settings on the cursor or in the passed in options.
|
4018 | * @param options Optional settings
|
4019 | * @param callback The result callback
|
4020 | * @returns Promise if no callback is passed
|
4021 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#count
|
4022 | */
|
4023 | count(callback: MongoCallback<number>): void;
|
4024 | count(applySkipLimit: boolean, callback: MongoCallback<number>): void;
|
4025 | count(options: CursorCommentOptions, callback: MongoCallback<number>): void;
|
4026 | count(applySkipLimit: boolean, options: CursorCommentOptions, callback: MongoCallback<number>): void;
|
4027 | count(applySkipLimit?: boolean, options?: CursorCommentOptions): Promise<number>;
|
4028 | /**
|
4029 | * Execute the explain for the cursor
|
4030 | * For backwards compatibility, a verbosity of true is interpreted as `allPlansExecution`
|
4031 | * and false as `queryPlanner`. Prior to server version 3.6, `aggregate()`
|
4032 | * ignores the verbosity parameter and executes in `queryPlanner`.
|
4033 | *
|
4034 | * @param verbosity An optional mode in which to run the explain.
|
4035 | * @param callback The result callback
|
4036 | * @returns Promise if no callback is passed
|
4037 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#explain
|
4038 | */
|
4039 | explain(verbosity?: string | boolean, callback?: MongoCallback<CursorResult>): Promise<CursorResult>;
|
4040 | explain(callback?: MongoCallback<CursorResult>): void;
|
4041 | /**
|
4042 | * Set the cursor query
|
4043 | *
|
4044 | * @param filter The filter object used for the cursor
|
4045 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#filter
|
4046 | */
|
4047 | filter(filter: object): Cursor<T>;
|
4048 | /**
|
4049 | * Iterates over all the documents for this cursor using the iterator, callback pattern.
|
4050 | *
|
4051 | * @param iterator The iteration callback
|
4052 | * @param callback The end callback
|
4053 | * @returns no callback supplied
|
4054 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#forEach
|
4055 | */
|
4056 | forEach(iterator: IteratorCallback<T>, callback: EndCallback): void;
|
4057 | forEach(iterator: IteratorCallback<T>): Promise<void>;
|
4058 | /**
|
4059 | * Check if there is any document still available in the cursor
|
4060 | *
|
4061 | * @param callback The result callback
|
4062 | * @returns Promise if no callback is passed
|
4063 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#hasNext
|
4064 | */
|
4065 | hasNext(): Promise<boolean>;
|
4066 | hasNext(callback: MongoCallback<boolean>): void;
|
4067 | /**
|
4068 | * Set the cursor hint
|
4069 | *
|
4070 | * @param hint If specified, then the query system will only consider plans using the hinted index.
|
4071 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#hint
|
4072 | */
|
4073 | hint(hint: string | object): Cursor<T>;
|
4074 | /**
|
4075 | * Is the cursor closed
|
4076 | *
|
4077 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#isClosed
|
4078 | */
|
4079 | isClosed(): boolean;
|
4080 | /**
|
4081 | * Set the limit for the cursor
|
4082 | *
|
4083 | * @param value The limit for the cursor query
|
4084 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#limit
|
4085 | */
|
4086 | limit(value: number): Cursor<T>;
|
4087 | /**
|
4088 | * Map all documents using the provided function
|
4089 | *
|
4090 | * @param transform The mapping transformation method
|
4091 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#map
|
4092 | */
|
4093 | map<U>(transform: (document: T) => U): Cursor<U>;
|
4094 | /**
|
4095 | * Set the cursor max
|
4096 | *
|
4097 | * @param max Specify a $max value to specify the exclusive upper bound for a specific index in order to constrain the results of find().
|
4098 | * The $max specifies the upper bound for all keys of a specific index in order.
|
4099 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#max
|
4100 | */
|
4101 | max(max: object): Cursor<T>;
|
4102 | /**
|
4103 | * Set a maxAwaitTimeMS on a tailing cursor query to allow to customize the timeout value for the option awaitData (Only supported on MongoDB 3.2 or higher, ignored otherwise)
|
4104 | *
|
4105 | * @param value Number of milliseconds to wait before aborting the tailed query
|
4106 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#maxAwaitTimeMS
|
4107 | */
|
4108 | maxAwaitTimeMS(value: number): Cursor<T>;
|
4109 | /**
|
4110 | * Set the cursor maxScan
|
4111 | *
|
4112 | * @param maxScan Constrains the query to only scan the specified number of documents when fulfilling the query
|
4113 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#maxScan
|
4114 | */
|
4115 | maxScan(maxScan: object): Cursor<T>;
|
4116 | /**
|
4117 | * Set a maxTimeMS on the cursor query, allowing for hard timeout limits on queries (Only supported on MongoDB 2.6 or higher)
|
4118 | *
|
4119 | * @param value Number of milliseconds to wait before aborting the query.
|
4120 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#maxTimeMS
|
4121 | */
|
4122 | maxTimeMS(value: number): Cursor<T>;
|
4123 | /**
|
4124 | * Set the cursor min
|
4125 | *
|
4126 | * @param min Specify a $min value to specify the inclusive lower bound for a specific index in order to constrain the results of find().
|
4127 | * The $min specifies the lower bound for all keys of a specific index in order.
|
4128 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#min
|
4129 | */
|
4130 | min(min: object): Cursor<T>;
|
4131 | /**
|
4132 | * Get the next available document from the cursor, returns null if no more documents are available.
|
4133 | *
|
4134 | * @param callback The result callback
|
4135 | * @returns Promise if no callback is passed
|
4136 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#next
|
4137 | */
|
4138 | next(): Promise<T | null>;
|
4139 | next(callback: MongoCallback<T | null>): void;
|
4140 | /**
|
4141 | * Sets a field projection for the query
|
4142 | *
|
4143 | * @param value The field projection object
|
4144 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#project
|
4145 | */
|
4146 | project<U = T>(value: SchemaMember<T, ProjectionOperators | number | boolean | any>): Cursor<U>;
|
4147 | /**
|
4148 | * The read() method pulls some data out of the internal buffer and returns it. If there is no data available, then it will return null.
|
4149 | *
|
4150 | * @param size Optional argument to specify how much data to read.
|
4151 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#read
|
4152 | */
|
4153 | read(size?: number): string | Buffer | void;
|
4154 | /**
|
4155 | * Set the cursor returnKey. If set to true, modifies the cursor to only return the index field or fields for the results of the query, rather than documents.
|
4156 | * If set to true and the query does not use an index to perform the read operation, the returned documents will not contain any fields.
|
4157 | *
|
4158 | * @param returnKey the returnKey value.
|
4159 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#returnKey
|
4160 | */
|
4161 | returnKey(returnKey: boolean): Cursor<T>;
|
4162 | /**
|
4163 | * Resets the cursor
|
4164 | *
|
4165 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#rewind
|
4166 | */
|
4167 | rewind(): void;
|
4168 | /**
|
4169 | * Set a node.js specific cursor option
|
4170 | *
|
4171 | * @param field The cursor option to set ['numberOfRetries', 'tailableRetryInterval'].
|
4172 | * @param value The field value
|
4173 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#setCursorOption
|
4174 | */
|
4175 | setCursorOption(field: string, value: object): Cursor<T>;
|
4176 | /**
|
4177 | * Set the ReadPreference for the cursor.
|
4178 | *
|
4179 | * @param readPreference The new read preference for the cursor
|
4180 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#setReadPreference
|
4181 | */
|
4182 | setReadPreference(readPreference: ReadPreferenceOrMode): Cursor<T>;
|
4183 | /**
|
4184 | * Set the cursor showRecordId
|
4185 | *
|
4186 | * @param showRecordId The $showDiskLoc option has now been deprecated and replaced with the showRecordId field. $showDiskLoc will still be accepted for OP_QUERY stye find.
|
4187 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#showRecordId
|
4188 | */
|
4189 | showRecordId(showRecordId: boolean): Cursor<T>;
|
4190 | /**
|
4191 | * Set the skip for the cursor
|
4192 | *
|
4193 | * @param value The skip for the cursor query.
|
4194 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#skip
|
4195 | */
|
4196 | skip(value: number): Cursor<T>;
|
4197 | /**
|
4198 | * Set the cursor snapshot
|
4199 | *
|
4200 | * @param snapshot The $snapshot operator prevents the cursor from returning a document more than once because an intervening write operation results in a move of the document.
|
4201 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#snapshot
|
4202 | */
|
4203 | snapshot(snapshot: object): Cursor<T>;
|
4204 | /**
|
4205 | * Sets the sort order of the cursor query
|
4206 | *
|
4207 | * @param keyOrList The key or keys set for the sort
|
4208 | * @param direction The direction of the sorting (1 or -1).
|
4209 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#sort
|
4210 | */
|
4211 | sort(keyOrList: string | Array<[string, number]> | SortOptionObject<T>, direction?: number): Cursor<T>;
|
4212 | /**
|
4213 | * Return a modified Readable stream including a possible transform method
|
4214 | *
|
4215 | * @param options Optional settings
|
4216 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#stream
|
4217 | */
|
4218 | stream(options?: { transform?: (document: T) => any }): Cursor<T>;
|
4219 | /**
|
4220 | * Returns an array of documents. The caller is responsible for making sure that there
|
4221 | * is enough memory to store the results. Note that the array only contains partial
|
4222 | * results when this cursor had been previously accessed. In that case,
|
4223 | * `cursor.rewind()` can be used to reset the cursor.
|
4224 | *
|
4225 | * @param callback The result callback
|
4226 | * @returns Promise if no callback is passed
|
4227 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#toArray
|
4228 | */
|
4229 | toArray(): Promise<T[]>;
|
4230 | toArray(callback: MongoCallback<T[]>): void;
|
4231 | /**
|
4232 | * Return a modified Readable stream that applies a given transform function, if supplied. If none supplied,
|
4233 | * returns a stream of unmodified docs.
|
4234 | *
|
4235 | * @param options Optional settings
|
4236 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#transformStream
|
4237 | */
|
4238 | transformStream(options?: { transform?: (document: T) => any }): Cursor<T>;
|
4239 | /**
|
4240 | * This is useful in certain cases where a stream is being consumed by a parser,
|
4241 | * which needs to "un-consume" some data that it has optimistically pulled out of the source, so that the stream can be passed on to some other party.
|
4242 | *
|
4243 | * @param chunk Chunk of data to unshift onto the read queue.
|
4244 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#unshift
|
4245 | */
|
4246 | unshift(chunk: Buffer | string): void;
|
4247 | }
|
4248 |
|
4249 | /**
|
4250 | * Options for Cursor.count() operations.
|
4251 | *
|
4252 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#count
|
4253 | */
|
4254 | export interface CursorCommentOptions {
|
4255 | skip?: number;
|
4256 | limit?: number;
|
4257 | maxTimeMS?: number;
|
4258 | hint?: string;
|
4259 | readPreference?: ReadPreferenceOrMode;
|
4260 | }
|
4261 |
|
4262 | /**
|
4263 | * The callback format for the forEach iterator method
|
4264 | *
|
4265 | * @param doc An emitted document for the iterator
|
4266 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#~iteratorCallback
|
4267 | */
|
4268 | export interface IteratorCallback<T> {
|
4269 | (doc: T): void;
|
4270 | }
|
4271 |
|
4272 | /**
|
4273 | * The callback error format for the forEach iterator method
|
4274 | *
|
4275 | * @param error An error instance representing the error during the execution.
|
4276 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Cursor.html#~endCallback
|
4277 | */
|
4278 | export interface EndCallback {
|
4279 | (error: MongoError): void;
|
4280 | }
|
4281 |
|
4282 | /**
|
4283 | * Returning object for the AggregationCursor result callback
|
4284 | *
|
4285 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#~resultCallback
|
4286 | */
|
4287 | export type AggregationCursorResult = object | null;
|
4288 | /**
|
4289 | * Creates a new Aggregation Cursor instance (INTERNAL TYPE, do not instantiate directly)
|
4290 | *
|
4291 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html
|
4292 | */
|
4293 | export class AggregationCursor<T = Default> extends Cursor<T> {
|
4294 | /**
|
4295 | * Set the batch size for the cursor
|
4296 | *
|
4297 | * @param value The number of documents to return per batch. See {@link https://docs.mongodb.com/manual/reference/command/aggregate aggregation documentation}.
|
4298 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#batchSize
|
4299 | */
|
4300 | batchSize(value: number): AggregationCursor<T>;
|
4301 | /**
|
4302 | * Clone the cursor
|
4303 | *
|
4304 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#clone
|
4305 | */
|
4306 | clone(): AggregationCursor<T>;
|
4307 | /**
|
4308 | * Close the cursor, sending a AggregationCursor command and emitting close.
|
4309 | *
|
4310 | * @param callback The result callback
|
4311 | * @returns Promise if no callback is passed
|
4312 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#close
|
4313 | */
|
4314 | close(): Promise<AggregationCursorResult>;
|
4315 | close(callback: MongoCallback<AggregationCursorResult>): void;
|
4316 | /**
|
4317 | * Iterates over all the documents for this cursor. As with `cursor.toArray()`,
|
4318 | * not all of the elements will be iterated if this cursor had been previously accessed.
|
4319 | * In that case, `cursor.rewind()` can be used to reset the cursor. However, unlike
|
4320 | * `cursor.toArray()`, the cursor will only hold a maximum of batch size elements
|
4321 | * at any given time if batch size is specified. Otherwise, the caller is responsible
|
4322 | * for making sure that the entire result can fit the memory.
|
4323 | *
|
4324 | * @param callback The result callback
|
4325 | * @deprecated use AggregationCursor.forEach() instead
|
4326 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#each
|
4327 | */
|
4328 | each(callback: MongoCallback<AggregationCursorResult>): void;
|
4329 | /**
|
4330 | * Execute the explain for the cursor.
|
4331 | * For backwards compatibility, a verbosity of true is interpreted as `allPlansExecution`
|
4332 | * and false as `queryPlanner`. Prior to server version 3.6, `aggregate()`
|
4333 | * ignores the verbosity parameter and executes in `queryPlanner`.
|
4334 | *
|
4335 | * @param verbosity An optional mode in which to run the explain
|
4336 | * @param callback The result callback
|
4337 | * @returns Promise if no callback is passed
|
4338 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#explain
|
4339 | */
|
4340 | explain(
|
4341 | verbosity?: string | boolean,
|
4342 | callback?: MongoCallback<AggregationCursorResult>,
|
4343 | ): Promise<AggregationCursorResult>;
|
4344 | explain(callback?: MongoCallback<AggregationCursorResult>): void;
|
4345 | /**
|
4346 | * Add a geoNear stage to the aggregation pipeline
|
4347 | *
|
4348 | * @param document The geoNear stage document
|
4349 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#geoNear
|
4350 | */
|
4351 | geoNear(document: object): AggregationCursor<T>;
|
4352 | /**
|
4353 | * Add a group stage to the aggregation pipeline
|
4354 | *
|
4355 | * @param document The group stage document
|
4356 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#group
|
4357 | */
|
4358 | group<U = T>(document: object): AggregationCursor<U>;
|
4359 | /**
|
4360 | * Check if there is any document still available in the cursor
|
4361 | *
|
4362 | * @param callback The result callback
|
4363 | * @returns Promise if no callback is passed
|
4364 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#hasNext
|
4365 | */
|
4366 | hasNext(): Promise<boolean>;
|
4367 | hasNext(callback: MongoCallback<boolean>): void;
|
4368 | /**
|
4369 | * Is the cursor closed
|
4370 | *
|
4371 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#isClosed
|
4372 | */
|
4373 | isClosed(): boolean;
|
4374 | /**
|
4375 | * Add a limit stage to the aggregation pipeline
|
4376 | *
|
4377 | * @param limit The state limit value
|
4378 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#limit
|
4379 | */
|
4380 | limit(value: number): AggregationCursor<T>;
|
4381 | /**
|
4382 | * Add a lookup stage to the aggregation pipeline
|
4383 | *
|
4384 | * @param document The lookup stage document
|
4385 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#lookup
|
4386 | */
|
4387 | lookup(document: object): AggregationCursor<T>;
|
4388 | /**
|
4389 | * Add a match stage to the aggregation pipeline
|
4390 | *
|
4391 | * @param document The match stage document
|
4392 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#match
|
4393 | */
|
4394 | match(document: object): AggregationCursor<T>;
|
4395 | /**
|
4396 | * Add a maxTimeMS stage to the aggregation pipeline
|
4397 | *
|
4398 | * @param value The state maxTimeMS value
|
4399 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#maxTimeMS
|
4400 | */
|
4401 | maxTimeMS(value: number): AggregationCursor<T>;
|
4402 | /**
|
4403 | * Get the next available document from the cursor, returns null if no more documents are available
|
4404 | *
|
4405 | * @param callback The result callback
|
4406 | * @returns Promise if no callback is passed
|
4407 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#next
|
4408 | */
|
4409 | next(): Promise<T | null>;
|
4410 | next(callback: MongoCallback<T | null>): void;
|
4411 | /**
|
4412 | * Add a out stage to the aggregation pipeline
|
4413 | *
|
4414 | * @param destination The destination name
|
4415 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#out
|
4416 | */
|
4417 | out(destination: string): AggregationCursor<T>;
|
4418 | /**
|
4419 | * Add a project stage to the aggregation pipeline
|
4420 | *
|
4421 | * @param document The project stage document
|
4422 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#project
|
4423 | */
|
4424 | project<U = T>(document: object): AggregationCursor<U>;
|
4425 | /**
|
4426 | * The `read()` method pulls some data out of the internal buffer and returns it. If there is no data available, then it will return null.
|
4427 | *
|
4428 | * @param size Optional argument to specify how much data to read
|
4429 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#read
|
4430 | */
|
4431 | read(size: number): string | Buffer | void;
|
4432 | /**
|
4433 | * Add a redact stage to the aggregation pipeline
|
4434 | *
|
4435 | * @param document The redact stage document.
|
4436 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#redact
|
4437 | */
|
4438 | redact(document: object): AggregationCursor<T>;
|
4439 | /**
|
4440 | * Resets the cursor
|
4441 | *
|
4442 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#rewind
|
4443 | */
|
4444 | rewind(): AggregationCursor<T>;
|
4445 | /**
|
4446 | * Add a skip stage to the aggregation pipeline
|
4447 | *
|
4448 | * @param value The state skip value
|
4449 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#setEncoding
|
4450 | */
|
4451 | skip(value: number): AggregationCursor<T>;
|
4452 | /**
|
4453 | * Add a sort stage to the aggregation pipeline
|
4454 | *
|
4455 | * @param document The sort stage document
|
4456 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#sort
|
4457 | */
|
4458 | sort(document: object): AggregationCursor<T>;
|
4459 | /**
|
4460 | * Returns an array of documents. The caller is responsible for making sure that there
|
4461 | * is enough memory to store the results. Note that the array only contain partial
|
4462 | * results when this cursor had been previously accessed. In that case,
|
4463 | * `cursor.rewind()` can be used to reset the cursor.
|
4464 | *
|
4465 | * @param callback The result callback
|
4466 | * @returns Promise if no callback is passed
|
4467 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#toArray
|
4468 | */
|
4469 | toArray(): Promise<T[]>;
|
4470 | toArray(callback: MongoCallback<T[]>): void;
|
4471 | /**
|
4472 | * This is useful in certain cases where a stream is being consumed by a parser, which needs to "un-consume" some data that it has optimistically
|
4473 | * pulled out of the source, so that the stream can be passed on to some other party.
|
4474 | *
|
4475 | * @param chunk Chunk of data to unshift onto the read queue
|
4476 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#unshift
|
4477 | */
|
4478 | unshift(chunk: Buffer | string): void;
|
4479 | /**
|
4480 | * Add a unwind stage to the aggregation pipeline
|
4481 | *
|
4482 | * @param field The unwind field name or stage document.
|
4483 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/AggregationCursor.html#unwind
|
4484 | */
|
4485 | unwind<U = T>(
|
4486 | field: string | { path: string; includeArrayIndex?: string; preserveNullAndEmptyArrays?: boolean },
|
4487 | ): AggregationCursor<U>;
|
4488 | }
|
4489 |
|
4490 | /**
|
4491 | * Result object from CommandCursor.resultCallback
|
4492 | *
|
4493 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/CommandCursor.html#~resultCallback
|
4494 | */
|
4495 | export type CommandCursorResult = object | null;
|
4496 | /**
|
4497 | * Creates a new Command Cursor instance (INTERNAL TYPE, do not instantiate directly)
|
4498 | *
|
4499 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/CommandCursor.html
|
4500 | */
|
4501 | export class CommandCursor extends Readable {
|
4502 | /**
|
4503 | * Set the batch size for the cursor.
|
4504 | *
|
4505 | * @param value The number of documents to return per batch. See {@link https://docs.mongodb.com/manual/reference/command/find/ find command documentation}.
|
4506 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/CommandCursor.html#batchSize
|
4507 | */
|
4508 | batchSize(value: number): CommandCursor;
|
4509 | /**
|
4510 | * Clone the cursor
|
4511 | *
|
4512 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/CommandCursor.html#clone
|
4513 | */
|
4514 | clone(): CommandCursor;
|
4515 | /**
|
4516 | * Close the cursor, sending a KillCursor command and emitting close.
|
4517 | *
|
4518 | * @param callback The result callback
|
4519 | * @returns Promise if no callback is passed
|
4520 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/CommandCursor.html#close
|
4521 | */
|
4522 | close(): Promise<CommandCursorResult>;
|
4523 | close(callback: MongoCallback<CommandCursorResult>): void;
|
4524 | /**
|
4525 | * Iterates over all the documents for this cursor. As with `cursor.toArray()`,
|
4526 | * not all of the elements will be iterated if this cursor had been previously accessed.
|
4527 | * In that case, `cursor.rewind()` can be used to reset the cursor. However, unlike
|
4528 | * `cursor.toArray()`, the cursor will only hold a maximum of batch size elements
|
4529 | * at any given time if batch size is specified. Otherwise, the caller is responsible
|
4530 | * for making sure that the entire result can fit the memory.
|
4531 | *
|
4532 | * @param callback The result callback
|
4533 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/CommandCursor.html#each
|
4534 | */
|
4535 | each(callback: MongoCallback<CommandCursorResult>): void;
|
4536 | /**
|
4537 | * Check if there is any document still available in the cursor
|
4538 | *
|
4539 | * @param callback The result callback
|
4540 | * @returns Promise if no callback is passed
|
4541 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/CommandCursor.html#hasNext
|
4542 | */
|
4543 | hasNext(): Promise<boolean>;
|
4544 | hasNext(callback: MongoCallback<boolean>): void;
|
4545 | /**
|
4546 | * Is the cursor closed
|
4547 | *
|
4548 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/CommandCursor.html#isClosed
|
4549 | */
|
4550 | isClosed(): boolean;
|
4551 | /**
|
4552 | * Add a maxTimeMS stage to the aggregation pipeline
|
4553 | *
|
4554 | * @param value The state maxTimeMS value
|
4555 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/CommandCursor.html#maxTimeMS
|
4556 | */
|
4557 | maxTimeMS(value: number): CommandCursor;
|
4558 | /**
|
4559 | * Get the next available document from the cursor, returns null if no more documents are available.
|
4560 | *
|
4561 | * @param callback The result callback
|
4562 | * @returns Promise if no callback is passed
|
4563 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/CommandCursor.html#next
|
4564 | */
|
4565 | next(): Promise<CommandCursorResult>;
|
4566 | next(callback: MongoCallback<CommandCursorResult>): void;
|
4567 | /**
|
4568 | * The `read()` method pulls some data out of the internal buffer and returns it. If there is no data available, then it will return null.
|
4569 | *
|
4570 | * @param size Optional argument to specify how much data to read
|
4571 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/CommandCursor.html#read
|
4572 | */
|
4573 | read(size: number): string | Buffer | void;
|
4574 | /**
|
4575 | * Resets the cursor
|
4576 | *
|
4577 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/CommandCursor.html#rewind
|
4578 | */
|
4579 | rewind(): CommandCursor;
|
4580 | /**
|
4581 | * Set the ReadPreference for the cursor
|
4582 | *
|
4583 | * @param readPreference The new read preference for the cursor
|
4584 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/CommandCursor.html#setReadPreference
|
4585 | */
|
4586 | setReadPreference(readPreference: ReadPreferenceOrMode): CommandCursor;
|
4587 | /**
|
4588 | * Returns an array of documents. The caller is responsible for making sure that there
|
4589 | * is enough memory to store the results. Note that the array only contain partial
|
4590 | * results when this cursor had been previously accessed.
|
4591 | *
|
4592 | * @param callback The result callback
|
4593 | * @returns Promise if no callback is passed
|
4594 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/CommandCursor.html#toArray
|
4595 | */
|
4596 | toArray(): Promise<any[]>;
|
4597 | toArray(callback: MongoCallback<any[]>): void;
|
4598 | /**
|
4599 | * This is useful in certain cases where a stream is being consumed by a parser, which needs to "un-consume" some data that it has
|
4600 | * optimistically pulled out of the source, so that the stream can be passed on to some other party.
|
4601 | *
|
4602 | * @param chunk Chunk of data to unshift onto the read queue
|
4603 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/CommandCursor.html#unshift
|
4604 | */
|
4605 | unshift(chunk: Buffer | string): void;
|
4606 | }
|
4607 |
|
4608 | /**
|
4609 | * Constructor for a streaming GridFS interface
|
4610 | *
|
4611 | * @param db A db handle
|
4612 | * @param options Optional settings
|
4613 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html
|
4614 | */
|
4615 | export class GridFSBucket extends EventEmitter {
|
4616 | constructor(db: Db, options?: GridFSBucketOptions);
|
4617 | /**
|
4618 | * Deletes a file with the given id
|
4619 | *
|
4620 | * @param id The id of the file doc
|
4621 | * @param callback The result callback
|
4622 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#delete
|
4623 | */
|
4624 | delete(id: ObjectId, callback?: GridFSBucketErrorCallback): void;
|
4625 | /**
|
4626 | * Removes this bucket's files collection, followed by its chunks collection
|
4627 | *
|
4628 | * @param callback The result callback
|
4629 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#drop
|
4630 | */
|
4631 | drop(callback?: GridFSBucketErrorCallback): void;
|
4632 | /**
|
4633 | * Convenience wrapper around find on the files collection
|
4634 | *
|
4635 | * @param filter The filter object used to find items inside the bucket
|
4636 | * @param options Optional settings for cursor
|
4637 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#find
|
4638 | */
|
4639 | find(filter: object, options?: GridFSBucketFindOptions): Cursor<any>;
|
4640 | /**
|
4641 | * Returns a readable stream (GridFSBucketReadStream) for streaming file data from GridFS.
|
4642 | *
|
4643 | * @param id The id of the file doc
|
4644 | * @param options Optional settings
|
4645 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#openDownloadStream
|
4646 | */
|
4647 | openDownloadStream(id: ObjectId, options?: { start: number; end: number }): GridFSBucketReadStream;
|
4648 | /**
|
4649 | * Returns a readable stream ({@link https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucketReadStream.html GridFSBucketReadStream}) for streaming the
|
4650 | * file with the given name from GridFS. If there are multiple files with
|
4651 | * the same name, this will stream the most recent file with the given name
|
4652 | * (as determined by the `uploadDate` field). You can set the `revision`
|
4653 | * option to change this behavior.
|
4654 | *
|
4655 | * @param filename The name of the file to stream
|
4656 | * @param options Optional settings
|
4657 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#openDownloadStreamByName
|
4658 | */
|
4659 | openDownloadStreamByName(
|
4660 | filename: string,
|
4661 | options?: { revision: number; start: number; end: number },
|
4662 | ): GridFSBucketReadStream;
|
4663 | /**
|
4664 | * Returns a writable stream (GridFSBucketWriteStream) for writing
|
4665 | * buffers to GridFS. The stream's `id` property contains the resulting
|
4666 | * file's id.
|
4667 | *
|
4668 | * @param filename The value of the `filename` key in the files doc
|
4669 | * @param options Optional settings
|
4670 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#openUploadStream
|
4671 | */
|
4672 | openUploadStream(filename: string, options?: GridFSBucketOpenUploadStreamOptions): GridFSBucketWriteStream;
|
4673 | /**
|
4674 | * Returns a writable stream ({@link https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucketWriteStream.html GridFSBucketWriteStream}) for writing
|
4675 | * buffers to GridFS for a custom file id. The stream's `id` property contains the resulting
|
4676 | * file's id.
|
4677 | *
|
4678 | * @param id A custom id used to identify the file
|
4679 | * @param filename The value of the `filename` key in the files doc
|
4680 | * @param options Optional settings
|
4681 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#openUploadStreamWithId
|
4682 | */
|
4683 | openUploadStreamWithId(
|
4684 | id: GridFSBucketWriteStreamId,
|
4685 | filename: string,
|
4686 | options?: GridFSBucketOpenUploadStreamOptions,
|
4687 | ): GridFSBucketWriteStream;
|
4688 | /**
|
4689 | * Renames the file with the given _id to the given string
|
4690 | *
|
4691 | * @param id The id of the file to rename
|
4692 | * @param filename New name for the file
|
4693 | * @param callback The result callback
|
4694 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#rename
|
4695 | */
|
4696 | rename(id: ObjectId, filename: string, callback?: GridFSBucketErrorCallback): void;
|
4697 | }
|
4698 |
|
4699 | /**
|
4700 | * Options for creating a new GridFSBucket
|
4701 | *
|
4702 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html
|
4703 | */
|
4704 | export interface GridFSBucketOptions {
|
4705 | bucketName?: string;
|
4706 | chunkSizeBytes?: number;
|
4707 | writeConcern?: WriteConcern;
|
4708 | readPreference?: ReadPreferenceOrMode;
|
4709 | }
|
4710 |
|
4711 | /**
|
4712 | * Callback format for all GridFSBucket methods that can accept a callback.
|
4713 | *
|
4714 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#~errorCallback
|
4715 | */
|
4716 | export interface GridFSBucketErrorCallback extends MongoCallback<void> {}
|
4717 |
|
4718 | /**
|
4719 | * Options for GridFSBucket.find() operations
|
4720 | *
|
4721 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#find
|
4722 | */
|
4723 | export interface GridFSBucketFindOptions {
|
4724 | batchSize?: number;
|
4725 | limit?: number;
|
4726 | maxTimeMS?: number;
|
4727 | noCursorTimeout?: boolean;
|
4728 | skip?: number;
|
4729 | sort?: object;
|
4730 | }
|
4731 |
|
4732 | /**
|
4733 | * Options for GridFSBucket.openUploadStream() operations
|
4734 | *
|
4735 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#openUploadStream
|
4736 | */
|
4737 | export interface GridFSBucketOpenUploadStreamOptions {
|
4738 | chunkSizeBytes?: number;
|
4739 | metadata?: object;
|
4740 | contentType?: string;
|
4741 | aliases?: string[];
|
4742 | }
|
4743 |
|
4744 | /**
|
4745 | * A readable stream that enables you to read buffers from GridFS.
|
4746 | * Do not instantiate this class directly. Use {@link https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#openDownloadStream openDownloadStream()} instead.
|
4747 | *
|
4748 | * @param chunks Handle for chunks collection
|
4749 | * @param files Handle for files collection
|
4750 | * @param readPreference The read preference to use
|
4751 | * @param filter The query to use to find the file document
|
4752 | * @param options Optional settings
|
4753 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucketReadStream.html
|
4754 | */
|
4755 | export class GridFSBucketReadStream extends Readable {
|
4756 | id: ObjectId;
|
4757 | constructor(
|
4758 | chunks: Collection<any>,
|
4759 | files: Collection<any>,
|
4760 | readPreference: object,
|
4761 | filter: object,
|
4762 | options?: GridFSBucketReadStreamOptions,
|
4763 | );
|
4764 | }
|
4765 |
|
4766 | /**
|
4767 | * Options for creating a new GridFSBucketReadStream
|
4768 | *
|
4769 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucketReadStream.html
|
4770 | */
|
4771 | export interface GridFSBucketReadStreamOptions {
|
4772 | sort?: number;
|
4773 | skip?: number;
|
4774 | start?: number;
|
4775 | end?: number;
|
4776 | }
|
4777 |
|
4778 | /**
|
4779 | * A writable stream that enables you to write buffers to GridFS.
|
4780 | * Do not instantiate this class directly. Use {@link https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#openUploadStream openUploadStream()} instead.
|
4781 | *
|
4782 | * @param bucket Handle for this stream's corresponding bucket
|
4783 | * @param filename The value of the `filename` key in the files doc
|
4784 | * @param options Optional settings
|
4785 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucketWriteStream.html
|
4786 | */
|
4787 | export class GridFSBucketWriteStream extends Writable {
|
4788 | id: GridFSBucketWriteStreamId;
|
4789 | constructor(bucket: GridFSBucket, filename: string, options?: GridFSBucketWriteStreamOptions);
|
4790 |
|
4791 | /**
|
4792 | * Places this write stream into an aborted state (all future writes fail)
|
4793 | * and deletes all chunks that have already been written.
|
4794 | *
|
4795 | * @param callback called when chunks are successfully removed or error occurred
|
4796 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucketWriteStream.html#abort
|
4797 | */
|
4798 | abort(callback?: GridFSBucketErrorCallback): void;
|
4799 | }
|
4800 |
|
4801 | /**
|
4802 | * Options for creating a new GridFSBucketWriteStream
|
4803 | *
|
4804 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucketWriteStream.html
|
4805 | */
|
4806 | export interface GridFSBucketWriteStreamOptions extends WriteConcern {
|
4807 | /**
|
4808 | * Custom file id for the GridFS file.
|
4809 | */
|
4810 | id?: GridFSBucketWriteStreamId;
|
4811 | /**
|
4812 | * The chunk size to use, in bytes
|
4813 | */
|
4814 | chunkSizeBytes?: number;
|
4815 | /**
|
4816 | * If true, disables adding an md5 field to file data
|
4817 | * @default false
|
4818 | */
|
4819 | disableMD5?: boolean;
|
4820 | }
|
4821 |
|
4822 | /**
|
4823 | * This is similar to Parameters but will work with a type which is
|
4824 | * a function or with a tuple specifying arguments, which are both
|
4825 | * common ways to define eventemitter events
|
4826 | */
|
4827 | type EventArguments<T> = [T] extends [(...args: infer U) => any] ? U : [T] extends [undefined] ? [] : [T];
|
4828 |
|
4829 | /**
|
4830 | * Type-safe event emitter from {@link https://github.com/andywer/typed-emitter}.
|
4831 | *
|
4832 | * Use it like this:
|
4833 | *
|
4834 | * interface MyEvents {
|
4835 | * error: (error: Error) => void
|
4836 | * message: (from: string, content: string) => void
|
4837 | * }
|
4838 | *
|
4839 | * const myEmitter = new EventEmitter() as TypedEmitter<MyEvents>
|
4840 | *
|
4841 | * myEmitter.on("message", (from, content) => {
|
4842 | * // ...
|
4843 | * })
|
4844 | *
|
4845 | * myEmitter.emit("error", "x") // <- Will catch this type error
|
4846 | */
|
4847 | declare class TypedEventEmitter<Events> {
|
4848 | addListener<E extends keyof Events>(event: E, listener: Events[E]): this;
|
4849 | on<E extends keyof Events>(event: E, listener: Events[E]): this;
|
4850 | once<E extends keyof Events>(event: E, listener: Events[E]): this;
|
4851 | prependListener<E extends keyof Events>(event: E, listener: Events[E]): this;
|
4852 | prependOnceListener<E extends keyof Events>(event: E, listener: Events[E]): this;
|
4853 |
|
4854 | off<E extends keyof Events>(event: E, listener: Events[E]): this;
|
4855 | removeAllListeners<E extends keyof Events>(event?: E): this;
|
4856 | removeListener<E extends keyof Events>(event: E, listener: Events[E]): this;
|
4857 |
|
4858 | emit<E extends keyof Events>(event: E, ...args: EventArguments<Events[E]>): boolean;
|
4859 | eventNames(): Array<keyof Events>;
|
4860 | rawListeners<E extends keyof Events>(event: E): Function[];
|
4861 | listeners<E extends keyof Events>(event: E): Function[];
|
4862 | listenerCount<E extends keyof Events>(event: E): number;
|
4863 |
|
4864 | getMaxListeners(): number;
|
4865 | setMaxListeners(maxListeners: number): this;
|
4866 | }
|
4867 |
|
4868 | /**
|
4869 | * Events emitted by ChangeStream instances
|
4870 | */
|
4871 | interface ChangeStreamEvents<TSchema extends { [key: string]: any } = DefaultSchema> {
|
4872 | /**
|
4873 | * Fired for each new matching change in the specified namespace. Attaching a `change`
|
4874 | * event listener to a Change Stream will switch the stream into flowing mode. Data will
|
4875 | * then be passed as soon as it is available.
|
4876 | *
|
4877 | * @param doc The changed document
|
4878 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ChangeStream.html#event:change
|
4879 | */
|
4880 | change: (doc: ChangeEvent<TSchema>) => void;
|
4881 | /**
|
4882 | * Change stream close event
|
4883 | *
|
4884 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ChangeStream.html#event:close
|
4885 | */
|
4886 | close: () => void;
|
4887 | /**
|
4888 | * Change stream end event
|
4889 | *
|
4890 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ChangeStream.html#event:end
|
4891 | */
|
4892 | end: () => void;
|
4893 | /**
|
4894 | * Fired when the stream encounters an error
|
4895 | *
|
4896 | * @param error The error encountered
|
4897 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ChangeStream.html#event:error
|
4898 | */
|
4899 | error: (err: MongoError) => void;
|
4900 | /**
|
4901 | * Emitted each time the change stream stores a new resume token.
|
4902 | *
|
4903 | * @param newToken The new resume token
|
4904 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ChangeStream.html#event:resumeTokenChanged
|
4905 | */
|
4906 | resumeTokenChanged: (newToken: ResumeToken) => void;
|
4907 | }
|
4908 |
|
4909 | /**
|
4910 | * Creates a new Change Stream instance. Normally created using `Collection.watch()`.
|
4911 | *
|
4912 | * @param parent The parent object that created this change stream
|
4913 | * @param pipeline An array of {@link https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/ aggregation pipeline stages} through which to pass change stream documents
|
4914 | * @param options Optional settings
|
4915 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ChangeStream.html
|
4916 | */
|
4917 | export class ChangeStream<TSchema extends { [key: string]: any } = DefaultSchema> extends TypedEventEmitter<
|
4918 | ChangeStreamEvents<TSchema>
|
4919 | > {
|
4920 | resumeToken: ResumeToken;
|
4921 |
|
4922 | constructor(parent: MongoClient | Db | Collection, pipeline: object[], options?: ChangeStreamOptions);
|
4923 |
|
4924 | /**
|
4925 | * Close the Change Stream
|
4926 | *
|
4927 | * @param callback The result callback
|
4928 | * @returns Promise if no callback is passed
|
4929 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ChangeStream.html#close
|
4930 | */
|
4931 | close(): Promise<any>;
|
4932 | close(callback: MongoCallback<any>): void;
|
4933 |
|
4934 | /**
|
4935 | * Check if there is any document still available in the Change Stream
|
4936 | *
|
4937 | * @param callback The result callback
|
4938 | * @returns Promise if no callback is passed
|
4939 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ChangeStream.html#hasNext
|
4940 | */
|
4941 | hasNext(): Promise<any>;
|
4942 | hasNext(callback: MongoCallback<any>): void;
|
4943 |
|
4944 | /**
|
4945 | * Is the change stream closed
|
4946 | *
|
4947 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ChangeStream.html#isClosed
|
4948 | */
|
4949 | isClosed(): boolean;
|
4950 |
|
4951 | /**
|
4952 | * Get the next available document from the Change Stream, returns null if no more documents are available.
|
4953 | *
|
4954 | * @param callback The result callback
|
4955 | * @returns Promise if no callback is passed
|
4956 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ChangeStream.html#next
|
4957 | */
|
4958 | next(): Promise<any>;
|
4959 | next(callback: MongoCallback<any>): void;
|
4960 |
|
4961 | /**
|
4962 | * Return a modified Readable stream including a possible transform method
|
4963 | *
|
4964 | * @param options Optional settings
|
4965 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/ChangeStream.html#stream
|
4966 | */
|
4967 | stream(options?: { transform?: Function }): Cursor;
|
4968 | }
|
4969 |
|
4970 | export class ResumeToken {}
|
4971 |
|
4972 | export type ChangeEventTypes =
|
4973 | | "insert"
|
4974 | | "delete"
|
4975 | | "replace"
|
4976 | | "update"
|
4977 | | "drop"
|
4978 | | "rename"
|
4979 | | "dropDatabase"
|
4980 | | "invalidate";
|
4981 | export interface ChangeEventBase<TSchema extends { [key: string]: any } = DefaultSchema> {
|
4982 | _id: ResumeToken;
|
4983 | /**
|
4984 | * We leave this off the base type so that we can differentiate
|
4985 | * by checking its value and get intelligent types on the other fields
|
4986 | */
|
4987 | // operationType: ChangeEventTypes;
|
4988 | ns: {
|
4989 | db: string;
|
4990 | coll: string;
|
4991 | };
|
4992 | clusterTime: Timestamp;
|
4993 | txnNumber?: number;
|
4994 | lsid?: {
|
4995 | id: any;
|
4996 | uid: any;
|
4997 | };
|
4998 | }
|
4999 | export interface ChangeEventCR<TSchema extends { [key: string]: any } = DefaultSchema>
|
5000 | extends ChangeEventBase<TSchema> {
|
5001 | operationType: "insert" | "replace";
|
5002 | fullDocument?: TSchema;
|
5003 | documentKey: {
|
5004 | _id: ExtractIdType<TSchema>;
|
5005 | };
|
5006 | }
|
5007 | type FieldUpdates<TSchema> = Partial<TSchema> & { [key: string]: any };
|
5008 | export interface ChangeEventUpdate<TSchema extends { [key: string]: any } = DefaultSchema>
|
5009 | extends ChangeEventBase<TSchema> {
|
5010 | operationType: "update";
|
5011 | updateDescription: {
|
5012 | /**
|
5013 | * This is an object with all changed fields; if they are nested,
|
5014 | * the keys will be paths, e.g. 'question.answer.0.text': 'new text'
|
5015 | */
|
5016 | updatedFields: FieldUpdates<TSchema>;
|
5017 | removedFields: Array<keyof TSchema | string>;
|
5018 | };
|
5019 | fullDocument?: TSchema;
|
5020 | documentKey: {
|
5021 | _id: ExtractIdType<TSchema>;
|
5022 | };
|
5023 | }
|
5024 | export interface ChangeEventDelete<TSchema extends { [key: string]: any } = DefaultSchema>
|
5025 | extends ChangeEventBase<TSchema> {
|
5026 | operationType: "delete";
|
5027 | documentKey: {
|
5028 | _id: ExtractIdType<TSchema>;
|
5029 | };
|
5030 | }
|
5031 | export interface ChangeEventRename<TSchema extends { [key: string]: any } = DefaultSchema>
|
5032 | extends ChangeEventBase<TSchema> {
|
5033 | operationType: "rename";
|
5034 | to: {
|
5035 | db: string;
|
5036 | coll: string;
|
5037 | };
|
5038 | }
|
5039 |
|
5040 | export interface ChangeEventOther<TSchema extends { [key: string]: any } = DefaultSchema>
|
5041 | extends ChangeEventBase<TSchema> {
|
5042 | operationType: "drop" | "dropDatabase";
|
5043 | }
|
5044 |
|
5045 | export interface ChangeEventInvalidate<TSchema extends { [key: string]: any } = DefaultSchema> {
|
5046 | _id: ResumeToken;
|
5047 | operationType: "invalidate";
|
5048 | clusterTime: Timestamp;
|
5049 | }
|
5050 |
|
5051 | export type ChangeEvent<TSchema extends object = { _id: ObjectId }> =
|
5052 | | ChangeEventCR<TSchema>
|
5053 | | ChangeEventUpdate<TSchema>
|
5054 | | ChangeEventDelete<TSchema>
|
5055 | | ChangeEventRename<TSchema>
|
5056 | | ChangeEventOther<TSchema>
|
5057 | | ChangeEventInvalidate<TSchema>;
|
5058 |
|
5059 | /**
|
5060 | * Options that can be passed to a `ChangeStream`.
|
5061 | * Note that `startAfter`, `resumeAfter`, and `startAtOperationTime` are all mutually exclusive, and the server will error if more than one is specified.
|
5062 | *
|
5063 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/global.html#ChangeStreamOptions
|
5064 | */
|
5065 | export interface ChangeStreamOptions {
|
5066 | fullDocument?: "default" | "updateLookup";
|
5067 | maxAwaitTimeMS?: number;
|
5068 | resumeAfter?: ResumeToken;
|
5069 | startAfter?: ResumeToken;
|
5070 | startAtOperationTime?: Timestamp;
|
5071 | batchSize?: number;
|
5072 | collation?: CollationDocument;
|
5073 | readPreference?: ReadPreferenceOrMode;
|
5074 | }
|
5075 |
|
5076 | type GridFSBucketWriteStreamId = string | number | object | ObjectId;
|
5077 |
|
5078 | export interface LoggerOptions {
|
5079 | /**
|
5080 | * Custom logger function
|
5081 | */
|
5082 | loggerLevel?: string;
|
5083 | /**
|
5084 | * Override default global log level.
|
5085 | */
|
5086 | logger?: log;
|
5087 | }
|
5088 |
|
5089 | export type log = (message?: string, state?: LoggerState) => void;
|
5090 |
|
5091 | export interface LoggerState {
|
5092 | type: string;
|
5093 | message: string;
|
5094 | className: string;
|
5095 | pid: number;
|
5096 | date: number;
|
5097 | }
|
5098 |
|
5099 | /**
|
5100 | * Creates a new Logger instance
|
5101 | *
|
5102 | * @param className The Class name associated with the logging instance
|
5103 | * @param options Optional settings
|
5104 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Logger.html
|
5105 | */
|
5106 | export class Logger {
|
5107 | constructor(className: string, options?: LoggerOptions);
|
5108 | /**
|
5109 | * Log a message at the debug level
|
5110 | *
|
5111 | * @param message The message to log
|
5112 | * @param object Additional meta data to log
|
5113 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Logger.html#debug
|
5114 | */
|
5115 | debug(message: string, object: LoggerState): void;
|
5116 | /**
|
5117 | * Log a message at the error level
|
5118 | *
|
5119 | * @param message The message to log
|
5120 | * @param object Additional meta data to log
|
5121 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Logger.html#error
|
5122 | */
|
5123 | error(message: string, object: LoggerState): void;
|
5124 | /**
|
5125 | * Log a message at the info level
|
5126 | *
|
5127 | * @param message The message to log
|
5128 | * @param object Additional meta data to log
|
5129 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Logger.html#info
|
5130 | */
|
5131 | info(message: string, object: LoggerState): void;
|
5132 | /**
|
5133 | * Is the logger set at debug level
|
5134 | *
|
5135 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Logger.html#isDebug
|
5136 | */
|
5137 | isDebug(): boolean;
|
5138 | /**
|
5139 | * Is the logger set at error level
|
5140 | *
|
5141 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Logger.html#isError
|
5142 | */
|
5143 | isError(): boolean;
|
5144 | /**
|
5145 | * Is the logger set at info level
|
5146 | *
|
5147 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Logger.html#isInfo
|
5148 | */
|
5149 | isInfo(): boolean;
|
5150 | /**
|
5151 | * Is the logger set at error level
|
5152 | *
|
5153 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Logger.html#isWarn
|
5154 | */
|
5155 | isWarn(): boolean;
|
5156 | /**
|
5157 | * Resets the logger to default settings, error and no filtered classes
|
5158 | *
|
5159 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Logger.html#.reset
|
5160 | */
|
5161 | static reset(): void;
|
5162 | /**
|
5163 | * Get the current logger function
|
5164 | *
|
5165 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Logger.html#.currentLogger
|
5166 | */
|
5167 | static currentLogger(): log;
|
5168 | /**
|
5169 | * Set the current logger function
|
5170 | *
|
5171 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Logger.html#.setCurrentLogger
|
5172 | */
|
5173 | static setCurrentLogger(log: log): void;
|
5174 | /**
|
5175 | * Set what classes to log.
|
5176 | *
|
5177 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Logger.html#.filter
|
5178 | */
|
5179 | static filter(type: string, values: string[]): void;
|
5180 | /**
|
5181 | * Set the current log level
|
5182 | *
|
5183 | * @see https://mongodb.github.io/node-mongodb-native/3.6/api/Logger.html#.setLevel
|
5184 | */
|
5185 | static setLevel(level: string): void;
|
5186 | }
|
5187 |
|
5188 | /**
|
5189 | * Possible fields for a collation document
|
5190 | *
|
5191 | * @see https://docs.mongodb.com/v3.6/reference/collation/#collation-document-fields
|
5192 | */
|
5193 | export interface CollationDocument {
|
5194 | locale: string;
|
5195 | strength?: number;
|
5196 | caseLevel?: boolean;
|
5197 | caseFirst?: string;
|
5198 | numericOrdering?: boolean;
|
5199 | alternate?: string;
|
5200 | maxVariable?: string;
|
5201 | backwards?: boolean;
|
5202 | normalization?: boolean;
|
5203 | }
|
5204 |
|
5205 | /**
|
5206 | * Possible indexes to create inside a collection
|
5207 | *
|
5208 | * @see https://docs.mongodb.com/v3.6/reference/command/createIndexes/
|
5209 | */
|
5210 | export interface IndexSpecification {
|
5211 | key: object;
|
5212 | name?: string;
|
5213 | background?: boolean;
|
5214 | unique?: boolean;
|
5215 | partialFilterExpression?: object;
|
5216 | sparse?: boolean;
|
5217 | expireAfterSeconds?: number;
|
5218 | storageEngine?: object;
|
5219 | weights?: object;
|
5220 | default_language?: string;
|
5221 | language_override?: string;
|
5222 | textIndexVersion?: number;
|
5223 | "2dsphereIndexVersion"?: number;
|
5224 | bits?: number;
|
5225 | min?: number;
|
5226 | max?: number;
|
5227 | bucketSize?: number;
|
5228 | collation?: CollationDocument;
|
5229 | }
|
5230 |
|
\ | No newline at end of file |