. Advertisement .
..3..
. Advertisement .
..4..
The error: “cursor.toArray is not a function collection.find() accepts at most two arguments unhandled promise rejections are deprecated while using .find()” is a common error that can show up in many ways. In this blog, we will go through some of the ways you can fix this issue. Read on.
How To Solve The Error: “cursor.toArray is not a function collection.find() accepts at most two arguments unhandled promise rejections are deprecated while using .find()”?
When utilizing nodejs with MongoDB and Mongoose 6.0, you may encounter the following issue.
(Use `node --trace-warnings ...` to show where the warning was created)
(node:13720) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--u
terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:13720) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Version 6.0 of Mongoose is affected by this problem. So all you have to do now is downgrade your mongoose version. To uninstall the present mongoose version, use npm uninstall mongoose, then npm i [email protected].8. This will install the correct version to fix your issue.
Approach 1: Simply downgrade the mongoose version
Version 6.0 of Mongoose is affected by this problem. So all you have to do now is downgrade your mongoose version.
To uninstall the present mongoose version, use npm uninstall mongoose, then npm i [email protected].8. This will install the correct version to fix your issue.
Approach 2: Utilize mongoose version 5.13.8
npm uninstall mongoose
npm i [email protected]
Conclusion
We hope you enjoyed our article about the error. With this knowledge, we know that you can fix your error: “cursor.toArray is not a function collection.find() accepts at most two arguments unhandled promise rejections are deprecated while using .find()” quickly by following these steps! If you still have any other questions about fixing this syntax error, please leave a comment below. Thank you for reading!
Leave a comment