You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The package wraps all of the driver's asynchronous operations that previously supported both promises and callbacks. All the wrapped APIs offer callback support via an optional callback argument alongside a Promise return value so projects with mixed usage will continue to work.
28
+
29
+
#### Example usage of equivalent callback and promise usage
30
+
31
+
After installing the package and modifying imports the following example demonstrates equivalent usages of either `async`/`await` syntax, `.then`/`.catch` chaining, or callbacks:
/** @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 */
/** @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 */
/** @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 */
/** Check if there is any document still available in the Change Stream */
640
-
hasNext(): Promise<boolean>;
641
-
/** @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 */
// Change streams must resume indefinitely while each resume event succeeds.
647
-
// This loop continues until either a change event is received or until a resume attempt
648
-
// fails.
649
-
// eslint-disable-next-line no-constant-condition
650
-
while(true){
642
+
// Change streams must resume indefinitely while each resume event succeeds.
643
+
// This loop continues until either a change event is received or until a resume attempt
644
+
// fails.
645
+
// eslint-disable-next-line no-constant-condition
646
+
while(true){
647
+
try{
648
+
consthasNext=awaitthis.cursor.hasNext();
649
+
returnhasNext;
650
+
}catch(error){
651
651
try{
652
-
consthasNext=awaitthis.cursor.hasNext();
653
-
returnhasNext;
652
+
awaitthis._processErrorIteratorMode(error);
654
653
}catch(error){
655
654
try{
656
-
awaitthis._processErrorIteratorMode(error);
657
-
}catch(error){
658
-
try{
659
-
awaitthis.close();
660
-
}catch{
661
-
// We are not concerned with errors from close()
662
-
}
663
-
throwerror;
655
+
awaitthis.close();
656
+
}catch{
657
+
// We are not concerned with errors from close()
664
658
}
659
+
throwerror;
665
660
}
666
661
}
667
-
},callback);
662
+
}
668
663
}
669
664
670
665
/** Get the next available document from the Change Stream. */
671
-
next(): Promise<TChange>;
672
-
/** @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 */
* Try to get the next available document from the Change Stream's cursor or `null` if an empty batch is returned
704
694
*/
705
-
tryNext(): Promise<Document|null>;
706
-
/** @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 */
/** @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 */
0 commit comments