Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the difference of a query with .exec and without?

I declare the next query:

      const User = await User.findOne().and([{
        "accounts.email": re.body.email
      },{
        status: 1
      }])

What is the difference if add .exec() at the end of the query?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As far as the functionality is concerned adding .exec() to async/await query wouldn’t make a difference.

But as per mongoose documentation, you "should" use .exec() as it will provide you with better stack trace.

Check – Should You Use exec() With await?

Without exec(), the stack trace does not include the calling code.

With exec(), the stack trace includes where in your code you called exec()

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading