JavaScript Native Driver - Which syntax is recommended: Promise or Async Functions?

I’m currently studying the basics of MongoDB’s native JavaScript drivers. I was just reading this post.

I understand both Promise and Async Functions are supported in the driver.

As I am new to MongoDB and async JavaScript in general, I have no particular preference in which style to use. To keep my project’s codebase consistent, I plan on picking one syntax and using it throughout the project.

Does MongoDB encourage the use of a particular syntax style? Again, I know it probably comes down to personal preference but as I have none, I am curious to know if one syntax is recommended over the another, and what are the reasons for it.

1 Like

Hey @Jack_Zhang! Great question - MongoDB makes has no opinions about whether you use Promise or Async functions. This is because under the hood they are the same thing! Async function are just syntactic sugar on top of Promises. This means there is no difference as far as MongoDB is concerned which one you choose. My personal recommendation would be to pick one and be consistent within your code base with which ever one you choose. Good luck!