Skip to content

Commit a983f14

Browse files
authoredSep 12, 2022
feat(NODE-4547): mark all callback APIs as deprecated (#3388)
1 parent 5c322b6 commit a983f14

13 files changed

+214
-107
lines changed
 

‎src/admin.ts

+30-19
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,15 @@ export interface AdminPrivate {
2929
* @public
3030
*
3131
* @example
32-
* ```js
33-
* const MongoClient = require('mongodb').MongoClient;
34-
* const test = require('assert');
35-
* // Connection url
36-
* const url = 'mongodb://localhost:27017';
37-
* // Database Name
38-
* const dbName = 'test';
32+
* ```ts
33+
* import { MongoClient } from 'mongodb';
3934
*
40-
* // Connect using MongoClient
41-
* MongoClient.connect(url, function(err, client) {
42-
* // Use the admin database for the operation
43-
* const adminDb = client.db(dbName).admin();
44-
*
45-
* // List all the available databases
46-
* adminDb.listDatabases(function(err, dbs) {
47-
* expect(err).to.not.exist;
48-
* test.ok(dbs.databases.length > 0);
49-
* client.close();
50-
* });
51-
* });
35+
* const client = new MongoClient('mongodb://localhost:27017');
36+
* const admin = client.db().admin();
37+
* const dbInfo = await admin.listDatabases();
38+
* for (const db of dbInfo.databases) {
39+
* console.log(db.name);
40+
* }
5241
* ```
5342
*/
5443
export class Admin {
@@ -71,8 +60,10 @@ export class Admin {
7160
* @param callback - An optional callback, a Promise will be returned if none is provided
7261
*/
7362
command(command: Document): Promise<Document>;
63+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
7464
command(command: Document, callback: Callback<Document>): void;
7565
command(command: Document, options: RunCommandOptions): Promise<Document>;
66+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
7667
command(command: Document, options: RunCommandOptions, callback: Callback<Document>): void;
7768
command(
7869
command: Document,
@@ -96,8 +87,10 @@ export class Admin {
9687
* @param callback - An optional callback, a Promise will be returned if none is provided
9788
*/
9889
buildInfo(): Promise<Document>;
90+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
9991
buildInfo(callback: Callback<Document>): void;
10092
buildInfo(options: CommandOperationOptions): Promise<Document>;
93+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
10194
buildInfo(options: CommandOperationOptions, callback: Callback<Document>): void;
10295
buildInfo(
10396
options?: CommandOperationOptions | Callback<Document>,
@@ -115,8 +108,10 @@ export class Admin {
115108
* @param callback - An optional callback, a Promise will be returned if none is provided
116109
*/
117110
serverInfo(): Promise<Document>;
111+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
118112
serverInfo(callback: Callback<Document>): void;
119113
serverInfo(options: CommandOperationOptions): Promise<Document>;
114+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
120115
serverInfo(options: CommandOperationOptions, callback: Callback<Document>): void;
121116
serverInfo(
122117
options?: CommandOperationOptions | Callback<Document>,
@@ -134,8 +129,10 @@ export class Admin {
134129
* @param callback - An optional callback, a Promise will be returned if none is provided
135130
*/
136131
serverStatus(): Promise<Document>;
132+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
137133
serverStatus(callback: Callback<Document>): void;
138134
serverStatus(options: CommandOperationOptions): Promise<Document>;
135+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
139136
serverStatus(options: CommandOperationOptions, callback: Callback<Document>): void;
140137
serverStatus(
141138
options?: CommandOperationOptions | Callback<Document>,
@@ -153,8 +150,10 @@ export class Admin {
153150
* @param callback - An optional callback, a Promise will be returned if none is provided
154151
*/
155152
ping(): Promise<Document>;
153+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
156154
ping(callback: Callback<Document>): void;
157155
ping(options: CommandOperationOptions): Promise<Document>;
156+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
158157
ping(options: CommandOperationOptions, callback: Callback<Document>): void;
159158
ping(
160159
options?: CommandOperationOptions | Callback<Document>,
@@ -174,12 +173,16 @@ export class Admin {
174173
* @param callback - An optional callback, a Promise will be returned if none is provided
175174
*/
176175
addUser(username: string): Promise<Document>;
176+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
177177
addUser(username: string, callback: Callback<Document>): void;
178178
addUser(username: string, password: string): Promise<Document>;
179+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
179180
addUser(username: string, password: string, callback: Callback<Document>): void;
180181
addUser(username: string, options: AddUserOptions): Promise<Document>;
182+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
181183
addUser(username: string, options: AddUserOptions, callback: Callback<Document>): void;
182184
addUser(username: string, password: string, options: AddUserOptions): Promise<Document>;
185+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
183186
addUser(
184187
username: string,
185188
password: string,
@@ -221,8 +224,10 @@ export class Admin {
221224
* @param callback - An optional callback, a Promise will be returned if none is provided
222225
*/
223226
removeUser(username: string): Promise<boolean>;
227+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
224228
removeUser(username: string, callback: Callback<boolean>): void;
225229
removeUser(username: string, options: RemoveUserOptions): Promise<boolean>;
230+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
226231
removeUser(username: string, options: RemoveUserOptions, callback: Callback<boolean>): void;
227232
removeUser(
228233
username: string,
@@ -247,8 +252,10 @@ export class Admin {
247252
* @param callback - An optional callback, a Promise will be returned if none is provided
248253
*/
249254
validateCollection(collectionName: string): Promise<Document>;
255+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
250256
validateCollection(collectionName: string, callback: Callback<Document>): void;
251257
validateCollection(collectionName: string, options: ValidateCollectionOptions): Promise<Document>;
258+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
252259
validateCollection(
253260
collectionName: string,
254261
options: ValidateCollectionOptions,
@@ -276,8 +283,10 @@ export class Admin {
276283
* @param callback - An optional callback, a Promise will be returned if none is provided
277284
*/
278285
listDatabases(): Promise<ListDatabasesResult>;
286+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
279287
listDatabases(callback: Callback<ListDatabasesResult>): void;
280288
listDatabases(options: ListDatabasesOptions): Promise<ListDatabasesResult>;
289+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
281290
listDatabases(options: ListDatabasesOptions, callback: Callback<ListDatabasesResult>): void;
282291
listDatabases(
283292
options?: ListDatabasesOptions | Callback<ListDatabasesResult>,
@@ -300,8 +309,10 @@ export class Admin {
300309
* @param callback - An optional callback, a Promise will be returned if none is provided
301310
*/
302311
replSetGetStatus(): Promise<Document>;
312+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
303313
replSetGetStatus(callback: Callback<Document>): void;
304314
replSetGetStatus(options: CommandOperationOptions): Promise<Document>;
315+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
305316
replSetGetStatus(options: CommandOperationOptions, callback: Callback<Document>): void;
306317
replSetGetStatus(
307318
options?: CommandOperationOptions | Callback<Document>,

‎src/bulk/common.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ export abstract class BulkOperationBase {
10651065
* Add a single insert document to the bulk operation
10661066
*
10671067
* @example
1068-
* ```js
1068+
* ```ts
10691069
* const bulkOp = collection.initializeOrderedBulkOp();
10701070
*
10711071
* // Adds three inserts to the bulkOp.
@@ -1089,7 +1089,7 @@ export abstract class BulkOperationBase {
10891089
* Returns a builder object used to complete the definition of the operation.
10901090
*
10911091
* @example
1092-
* ```js
1092+
* ```ts
10931093
* const bulkOp = collection.initializeOrderedBulkOp();
10941094
*
10951095
* // Add an updateOne to the bulkOp
@@ -1247,8 +1247,11 @@ export abstract class BulkOperationBase {
12471247
}
12481248

12491249
execute(options?: BulkWriteOptions): Promise<BulkWriteResult>;
1250+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
12501251
execute(callback: Callback<BulkWriteResult>): void;
1252+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
12511253
execute(options: BulkWriteOptions | undefined, callback: Callback<BulkWriteResult>): void;
1254+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
12521255
execute(
12531256
options?: BulkWriteOptions | Callback<BulkWriteResult>,
12541257
callback?: Callback<BulkWriteResult>

‎src/change_stream.ts

+4
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ export class ChangeStream<
645645

646646
/** Check if there is any document still available in the Change Stream */
647647
hasNext(): Promise<boolean>;
648+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
648649
hasNext(callback: Callback<boolean>): void;
649650
hasNext(callback?: Callback): Promise<boolean> | void {
650651
this._setIsIterator();
@@ -675,6 +676,7 @@ export class ChangeStream<
675676

676677
/** Get the next available document from the Change Stream. */
677678
next(): Promise<TChange>;
679+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
678680
next(callback: Callback<TChange>): void;
679681
next(callback?: Callback<TChange>): Promise<TChange> | void {
680682
this._setIsIterator();
@@ -709,6 +711,7 @@ export class ChangeStream<
709711
* Try to get the next available document from the Change Stream's cursor or `null` if an empty batch is returned
710712
*/
711713
tryNext(): Promise<Document | null>;
714+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
712715
tryNext(callback: Callback<Document | null>): void;
713716
tryNext(callback?: Callback<Document | null>): Promise<Document | null> | void {
714717
this._setIsIterator();
@@ -744,6 +747,7 @@ export class ChangeStream<
744747

745748
/** Close the Change Stream */
746749
close(): Promise<void>;
750+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
747751
close(callback: Callback): void;
748752
close(callback?: Callback): Promise<void> | void {
749753
this[kClosed] = true;

‎src/collection.ts

+96-39
Large diffs are not rendered by default.

‎src/cursor/abstract_cursor.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ export abstract class AbstractCursor<
317317
}
318318

319319
hasNext(): Promise<boolean>;
320+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
320321
hasNext(callback: Callback<boolean>): void;
321322
hasNext(callback?: Callback<boolean>): Promise<boolean> | void {
322323
return maybePromise(callback, done => {
@@ -344,7 +345,9 @@ export abstract class AbstractCursor<
344345

345346
/** Get the next available document from the cursor, returns null if no more documents are available. */
346347
next(): Promise<TSchema | null>;
348+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
347349
next(callback: Callback<TSchema | null>): void;
350+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
348351
next(callback?: Callback<TSchema | null>): Promise<TSchema | null> | void;
349352
next(callback?: Callback<TSchema | null>): Promise<TSchema | null> | void {
350353
return maybePromise(callback, done => {
@@ -360,6 +363,7 @@ export abstract class AbstractCursor<
360363
* Try to get the next available document from the cursor or `null` if an empty batch is returned
361364
*/
362365
tryNext(): Promise<TSchema | null>;
366+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
363367
tryNext(callback: Callback<TSchema | null>): void;
364368
tryNext(callback?: Callback<TSchema | null>): Promise<TSchema | null> | void {
365369
return maybePromise(callback, done => {
@@ -378,6 +382,7 @@ export abstract class AbstractCursor<
378382
* @param callback - The end callback.
379383
*/
380384
forEach(iterator: (doc: TSchema) => boolean | void): Promise<void>;
385+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
381386
forEach(iterator: (doc: TSchema) => boolean | void, callback: Callback<void>): void;
382387
forEach(
383388
iterator: (doc: TSchema) => boolean | void,
@@ -423,13 +428,14 @@ export abstract class AbstractCursor<
423428
}
424429

425430
close(): Promise<void>;
431+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
426432
close(callback: Callback): void;
427433
/**
428434
* @deprecated options argument is deprecated
429435
*/
430436
close(options: CursorCloseOptions): Promise<void>;
431437
/**
432-
* @deprecated options argument is deprecated
438+
* @deprecated options argument is deprecated. Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance
433439
*/
434440
close(options: CursorCloseOptions, callback: Callback): void;
435441
close(options?: CursorCloseOptions | Callback, callback?: Callback): Promise<void> | void {
@@ -451,6 +457,7 @@ export abstract class AbstractCursor<
451457
* @param callback - The result callback.
452458
*/
453459
toArray(): Promise<TSchema[]>;
460+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
454461
toArray(callback: Callback<TSchema[]>): void;
455462
toArray(callback?: Callback<TSchema[]>): Promise<TSchema[]> | void {
456463
return maybePromise(callback, done => {

‎src/cursor/aggregation_cursor.ts

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export class AggregationCursor<TSchema = any> extends AbstractCursor<TSchema> {
7878

7979
/** Execute the explain for the cursor */
8080
explain(): Promise<Document>;
81+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
8182
explain(callback: Callback): void;
8283
explain(verbosity: ExplainVerbosityLike): Promise<Document>;
8384
explain(

‎src/cursor/find_cursor.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
122122
* @deprecated Use `collection.estimatedDocumentCount` or `collection.countDocuments` instead
123123
*/
124124
count(): Promise<number>;
125-
/** @deprecated Use `collection.estimatedDocumentCount` or `collection.countDocuments` instead */
125+
/** @deprecated Use `collection.estimatedDocumentCount` or `collection.countDocuments` instead. Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
126126
count(callback: Callback<number>): void;
127-
/** @deprecated Use `collection.estimatedDocumentCount` or `collection.countDocuments` instead */
127+
/** @deprecated Use `collection.estimatedDocumentCount` or `collection.countDocuments` instead. */
128128
count(options: CountOptions): Promise<number>;
129-
/** @deprecated Use `collection.estimatedDocumentCount` or `collection.countDocuments` instead */
129+
/** @deprecated Use `collection.estimatedDocumentCount` or `collection.countDocuments` instead. Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
130130
count(options: CountOptions, callback: Callback<number>): void;
131131
count(
132132
options?: CountOptions | Callback<number>,
@@ -155,6 +155,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
155155

156156
/** Execute the explain for the cursor */
157157
explain(): Promise<Document>;
158+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
158159
explain(callback: Callback): void;
159160
explain(verbosity?: ExplainVerbosityLike): Promise<Document>;
160161
explain(

‎src/db.ts

+44-13
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,21 @@ export interface DbOptions extends BSONSerializeOptions, WriteConcernOptions, Lo
110110
* @public
111111
*
112112
* @example
113-
* ```js
114-
* const { MongoClient } = require('mongodb');
115-
* // Connection url
116-
* const url = 'mongodb://localhost:27017';
117-
* // Database Name
118-
* const dbName = 'test';
119-
* // Connect using MongoClient
120-
* MongoClient.connect(url, function(err, client) {
121-
* // Select the database by name
122-
* const testDb = client.db(dbName);
123-
* client.close();
124-
* });
113+
* ```ts
114+
* import { MongoClient } from 'mongodb';
115+
*
116+
* interface Pet {
117+
* name: string;
118+
* kind: 'dog' | 'cat' | 'fish';
119+
* }
120+
*
121+
* const client = new MongoClient('mongodb://localhost:27017');
122+
* const db = client.db();
123+
*
124+
* // Create a collection that validates our union
125+
* await db.createCollection<Pet>('pets', {
126+
* validator: { $expr: { $in: ['$kind', ['dog', 'cat', 'fish']] } }
127+
* })
125128
* ```
126129
*/
127130
export class Db {
@@ -238,10 +241,12 @@ export class Db {
238241
name: string,
239242
options?: CreateCollectionOptions
240243
): Promise<Collection<TSchema>>;
244+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
241245
createCollection<TSchema extends Document = Document>(
242246
name: string,
243247
callback: Callback<Collection<TSchema>>
244248
): void;
249+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
245250
createCollection<TSchema extends Document = Document>(
246251
name: string,
247252
options: CreateCollectionOptions | undefined,
@@ -272,8 +277,10 @@ export class Db {
272277
* @param callback - An optional callback, a Promise will be returned if none is provided
273278
*/
274279
command(command: Document): Promise<Document>;
280+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
275281
command(command: Document, callback: Callback<Document>): void;
276282
command(command: Document, options: RunCommandOptions): Promise<Document>;
283+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
277284
command(command: Document, options: RunCommandOptions, callback: Callback<Document>): void;
278285
command(
279286
command: Document,
@@ -347,8 +354,10 @@ export class Db {
347354
* @param callback - An optional callback, a Promise will be returned if none is provided
348355
*/
349356
stats(): Promise<Document>;
357+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
350358
stats(callback: Callback<Document>): void;
351359
stats(options: DbStatsOptions): Promise<Document>;
360+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
352361
stats(options: DbStatsOptions, callback: Callback<Document>): void;
353362
stats(
354363
options?: DbStatsOptions | Callback<Document>,
@@ -404,6 +413,7 @@ export class Db {
404413
fromCollection: string,
405414
toCollection: string
406415
): Promise<Collection<TSchema>>;
416+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
407417
renameCollection<TSchema extends Document = Document>(
408418
fromCollection: string,
409419
toCollection: string,
@@ -414,6 +424,7 @@ export class Db {
414424
toCollection: string,
415425
options: RenameOptions
416426
): Promise<Collection<TSchema>>;
427+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
417428
renameCollection<TSchema extends Document = Document>(
418429
fromCollection: string,
419430
toCollection: string,
@@ -453,8 +464,10 @@ export class Db {
453464
* @param callback - An optional callback, a Promise will be returned if none is provided
454465
*/
455466
dropCollection(name: string): Promise<boolean>;
467+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
456468
dropCollection(name: string, callback: Callback<boolean>): void;
457469
dropCollection(name: string, options: DropCollectionOptions): Promise<boolean>;
470+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
458471
dropCollection(name: string, options: DropCollectionOptions, callback: Callback<boolean>): void;
459472
dropCollection(
460473
name: string,
@@ -477,8 +490,10 @@ export class Db {
477490
* @param callback - An optional callback, a Promise will be returned if none is provided
478491
*/
479492
dropDatabase(): Promise<boolean>;
493+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
480494
dropDatabase(callback: Callback<boolean>): void;
481495
dropDatabase(options: DropDatabaseOptions): Promise<boolean>;
496+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
482497
dropDatabase(options: DropDatabaseOptions, callback: Callback<boolean>): void;
483498
dropDatabase(
484499
options?: DropDatabaseOptions | Callback<boolean>,
@@ -500,8 +515,10 @@ export class Db {
500515
* @param callback - An optional callback, a Promise will be returned if none is provided
501516
*/
502517
collections(): Promise<Collection[]>;
518+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
503519
collections(callback: Callback<Collection[]>): void;
504520
collections(options: ListCollectionsOptions): Promise<Collection[]>;
521+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
505522
collections(options: ListCollectionsOptions, callback: Callback<Collection[]>): void;
506523
collections(
507524
options?: ListCollectionsOptions | Callback<Collection[]>,
@@ -525,12 +542,14 @@ export class Db {
525542
* @param callback - An optional callback, a Promise will be returned if none is provided
526543
*/
527544
createIndex(name: string, indexSpec: IndexSpecification): Promise<string>;
528-
createIndex(name: string, indexSpec: IndexSpecification, callback?: Callback<string>): void;
545+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
546+
createIndex(name: string, indexSpec: IndexSpecification, callback: Callback<string>): void;
529547
createIndex(
530548
name: string,
531549
indexSpec: IndexSpecification,
532550
options: CreateIndexesOptions
533551
): Promise<string>;
552+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
534553
createIndex(
535554
name: string,
536555
indexSpec: IndexSpecification,
@@ -561,12 +580,16 @@ export class Db {
561580
* @param callback - An optional callback, a Promise will be returned if none is provided
562581
*/
563582
addUser(username: string): Promise<Document>;
583+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
564584
addUser(username: string, callback: Callback<Document>): void;
565585
addUser(username: string, password: string): Promise<Document>;
586+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
566587
addUser(username: string, password: string, callback: Callback<Document>): void;
567588
addUser(username: string, options: AddUserOptions): Promise<Document>;
589+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
568590
addUser(username: string, options: AddUserOptions, callback: Callback<Document>): void;
569591
addUser(username: string, password: string, options: AddUserOptions): Promise<Document>;
592+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
570593
addUser(
571594
username: string,
572595
password: string,
@@ -606,8 +629,10 @@ export class Db {
606629
* @param callback - An optional callback, a Promise will be returned if none is provided
607630
*/
608631
removeUser(username: string): Promise<boolean>;
632+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
609633
removeUser(username: string, callback: Callback<boolean>): void;
610634
removeUser(username: string, options: RemoveUserOptions): Promise<boolean>;
635+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
611636
removeUser(username: string, options: RemoveUserOptions, callback: Callback<boolean>): void;
612637
removeUser(
613638
username: string,
@@ -631,11 +656,13 @@ export class Db {
631656
* @param callback - An optional callback, a Promise will be returned if none is provided
632657
*/
633658
setProfilingLevel(level: ProfilingLevel): Promise<ProfilingLevel>;
659+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
634660
setProfilingLevel(level: ProfilingLevel, callback: Callback<ProfilingLevel>): void;
635661
setProfilingLevel(
636662
level: ProfilingLevel,
637663
options: SetProfilingLevelOptions
638664
): Promise<ProfilingLevel>;
665+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
639666
setProfilingLevel(
640667
level: ProfilingLevel,
641668
options: SetProfilingLevelOptions,
@@ -662,8 +689,10 @@ export class Db {
662689
* @param callback - An optional callback, a Promise will be returned if none is provided
663690
*/
664691
profilingLevel(): Promise<string>;
692+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
665693
profilingLevel(callback: Callback<string>): void;
666694
profilingLevel(options: ProfilingLevelOptions): Promise<string>;
695+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
667696
profilingLevel(options: ProfilingLevelOptions, callback: Callback<string>): void;
668697
profilingLevel(
669698
options?: ProfilingLevelOptions | Callback<string>,
@@ -686,8 +715,10 @@ export class Db {
686715
* @param callback - An optional callback, a Promise will be returned if none is provided
687716
*/
688717
indexInformation(name: string): Promise<Document>;
718+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
689719
indexInformation(name: string, callback: Callback<Document>): void;
690720
indexInformation(name: string, options: IndexInformationOptions): Promise<Document>;
721+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
691722
indexInformation(
692723
name: string,
693724
options: IndexInformationOptions,

‎src/gridfs/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export class GridFSBucket extends TypedEventEmitter<GridFSBucketEvents> {
141141
* @param id - The id of the file doc
142142
*/
143143
delete(id: ObjectId): Promise<void>;
144+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
144145
delete(id: ObjectId, callback: Callback<void>): void;
145146
delete(id: ObjectId, callback?: Callback<void>): Promise<void> | void {
146147
return maybePromise(callback, callback => {
@@ -211,6 +212,7 @@ export class GridFSBucket extends TypedEventEmitter<GridFSBucketEvents> {
211212
* @param filename - new name for the file
212213
*/
213214
rename(id: ObjectId, filename: string): Promise<void>;
215+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
214216
rename(id: ObjectId, filename: string, callback: Callback<void>): void;
215217
rename(id: ObjectId, filename: string, callback?: Callback<void>): Promise<void> | void {
216218
return maybePromise(callback, callback => {
@@ -232,6 +234,7 @@ export class GridFSBucket extends TypedEventEmitter<GridFSBucketEvents> {
232234

233235
/** Removes this bucket's files collection, followed by its chunks collection. */
234236
drop(): Promise<void>;
237+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
235238
drop(callback: Callback<void>): void;
236239
drop(callback?: Callback<void>): Promise<void> | void {
237240
return maybePromise(callback, callback => {

‎src/gridfs/upload.ts

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export class GridFSBucketWriteStream extends Writable implements NodeJS.Writable
146146
* @param callback - called when chunks are successfully removed or error occurred
147147
*/
148148
abort(): Promise<void>;
149+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
149150
abort(callback: Callback<void>): void;
150151
abort(callback?: Callback<void>): Promise<void> | void {
151152
return maybePromise(callback, callback => {

‎src/mongo_client.ts

+13-29
Original file line numberDiff line numberDiff line change
@@ -321,36 +321,15 @@ const kOptions = Symbol('options');
321321
* The programmatically provided options take precedence over the URI options.
322322
*
323323
* @example
324-
* ```js
325-
* // Connect using a MongoClient instance
326-
* const MongoClient = require('mongodb').MongoClient;
327-
* const test = require('assert');
328-
* // Connection url
329-
* const url = 'mongodb://localhost:27017';
330-
* // Database Name
331-
* const dbName = 'test';
332-
* // Connect using MongoClient
333-
* const mongoClient = new MongoClient(url);
334-
* mongoClient.connect(function(err, client) {
335-
* const db = client.db(dbName);
336-
* client.close();
337-
* });
338-
* ```
324+
* ```ts
325+
* import { MongoClient } from 'mongodb';
339326
*
340-
* @example
341-
* ```js
342-
* // Connect using the MongoClient.connect static method
343-
* const MongoClient = require('mongodb').MongoClient;
344-
* const test = require('assert');
345-
* // Connection url
346-
* const url = 'mongodb://localhost:27017';
347-
* // Database Name
348-
* const dbName = 'test';
349-
* // Connect using MongoClient
350-
* MongoClient.connect(url, function(err, client) {
351-
* const db = client.db(dbName);
352-
* client.close();
353-
* });
327+
* // Enable command monitoring for debugging
328+
* const client = new MongoClient('mongodb://localhost:27017', { monitorCommands: true });
329+
*
330+
* client.on('commandStarted', started => console.log(started));
331+
* client.db().collection('pets');
332+
* await client.insertOne({ name: 'spot', kind: 'dog' });
354333
* ```
355334
*/
356335
export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
@@ -451,6 +430,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
451430
* @see docs.mongodb.org/manual/reference/connection-string/
452431
*/
453432
connect(): Promise<this>;
433+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
454434
connect(callback: Callback<this>): void;
455435
connect(callback?: Callback<this>): Promise<this> | void {
456436
if (callback && typeof callback !== 'function') {
@@ -472,8 +452,10 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
472452
* @param callback - An optional callback, a Promise will be returned if none is provided
473453
*/
474454
close(): Promise<void>;
455+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
475456
close(callback: Callback<void>): void;
476457
close(force: boolean): Promise<void>;
458+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
477459
close(force: boolean, callback: Callback<void>): void;
478460
close(
479461
forceOrCallback?: boolean | Callback<void>,
@@ -588,8 +570,10 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
588570
* @see https://docs.mongodb.org/manual/reference/connection-string/
589571
*/
590572
static connect(url: string): Promise<MongoClient>;
573+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
591574
static connect(url: string, callback: Callback<MongoClient>): void;
592575
static connect(url: string, options: MongoClientOptions): Promise<MongoClient>;
576+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
593577
static connect(url: string, options: MongoClientOptions, callback: Callback<MongoClient>): void;
594578
static connect(
595579
url: string,

‎src/sessions.ts

+4
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,10 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
245245
* @param callback - Optional callback for completion of this operation
246246
*/
247247
endSession(): Promise<void>;
248+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
248249
endSession(callback: Callback<void>): void;
249250
endSession(options: EndSessionOptions): Promise<void>;
251+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
250252
endSession(options: EndSessionOptions, callback: Callback<void>): void;
251253
endSession(
252254
options?: EndSessionOptions | Callback<void>,
@@ -433,6 +435,7 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
433435
* @param callback - An optional callback, a Promise will be returned if none is provided
434436
*/
435437
commitTransaction(): Promise<Document>;
438+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
436439
commitTransaction(callback: Callback<Document>): void;
437440
commitTransaction(callback?: Callback<Document>): Promise<Document> | void {
438441
return maybePromise(callback, cb => endTransaction(this, 'commitTransaction', cb));
@@ -444,6 +447,7 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
444447
* @param callback - An optional callback, a Promise will be returned if none is provided
445448
*/
446449
abortTransaction(): Promise<Document>;
450+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
447451
abortTransaction(callback: Callback<Document>): void;
448452
abortTransaction(callback?: Callback<Document>): Promise<Document> | void {
449453
return maybePromise(callback, cb => endTransaction(this, 'abortTransaction', cb));

‎src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ export const DEFAULT_PK_FACTORY = {
12331233
* @public
12341234
*
12351235
* @example
1236-
* ```js
1236+
* ```ts
12371237
* process.on('warning', (warning) => {
12381238
* if (warning.code === MONGODB_WARNING_CODE) console.error('Ah an important warning! :)')
12391239
* })

0 commit comments

Comments
 (0)
Please sign in to comment.