Skip to content

Commit a983f14

Browse files
authored
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;

0 commit comments

Comments
 (0)