From the course: MongoDB Node.js Developer Associate Cert Prep

Connecting to MongoDB in Node.js review

- In this unit, you learned what a MongoDB driver is and how to connect a MongoDB database to a Node.js application by using a driver. You also learned how to troubleshoot common connection errors. When we run a Node.js application that connects to MongoDB, the application requires a set of libraries to interact with our MongoDB instance. These libraries are referred to as drivers. MongoDB provides a Node.js driver for asynchronous application code. Before we connected our application to our Atlas cluster, we first had to install the MongoDB driver by using the NPM Package Manager. Then we used the connection string from Atlas to create a connection between our application and the database. We used a single MongoClient instance, because creating MongoClients is resource-intensive. Creating a MongoClient for each database request will lead to performance degradation. Finally, you learned how to troubleshoot common connection issues, such as network access errors and user authentication errors. This knowledge gives you the foundation to troubleshoot the most common connection problems. Now that you can successfully connect your database to your Node.js application by using a connection string, try implementing CRUD methods and performing aggregations. To do this, check out our units on CRUD or take a look at the MongoDB documentation. Congratulations on completing this unit. Until next time, keep coding.

Contents