Skip to content
Advertisement

countDocuments() is not working in api call

I am trying to get a count of products using api calls but in postman its keep loading

JavaScript

without async and await also its not working

I try to catch the error and i got this error in postman

JavaScript

code to catch error:

JavaScript

Advertisement

Answer

I think in Mongoose operations you want to either await or provide a callback, but not both. Attempting to do both causes it to internally execute the query twice.

Try just:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement