
Mongodb+srv:// : an instance of the MongoDB client in your app So then my simpler, final URI looks like: For simplicity’s sake, I personally like to remove everything after the final slash (the database name, and retry writes setting) and just deal with that in code. I usually trip up on the fine print: note that both the username/password and database are placeholders, and you’ll need to update them with your desired values. Since we’re using the Node SDK, we’ll choose “Node.js” and the most recent version (4.0 or later as of May 2022).Ĭopy that URI, and we’re ready for the final step.

You can find it by heading to your Atlas homepage, finding your database, and clicking “connect.”Ĭhoose “Connect your application” and configure the driver and version. Your connection URI is how MongoDB knows what cluster to connect to among a sea of Atlas instances. The UI is pretty simple and allows for comments-and a sort of self-destruction feature: Get your unique connection URI Head over to the “Network Access” setting in that same security tab, and there you’ll be able to add a whitelisted IP address. Whitelist the IP address of the server or client you want to connect You can choose from types of auth, specific roles and privileges, and even restrict users to specific datasets. Click “add a new database user” and you’ll be presented with a lot of options: To create a database user, head over to your “Database Access” tab under the “Security” section. This makes things more secure as you can allocate individual permissions, see which users did what to which data, etc. Like other databases, MongoDB requires you to create a database user (not to be confused with the user on your Atlas account) to be registered for different access patterns. Npm install -D the driver installed, you’ve only got a few steps left before you can write queries: configuring database access, figuring out your unique database URI, and creating an instance of the MongoDB client with it in your application. Note that if you’re using TypeScript in your project you’ll need to use the driver’s definitions: A simple npm install in your project directory does it: Install MongoDB’s Node.js driverįirst, make sure the mongodb package is installed (whether you’re making queries from the client or the server). Step one to querying your database is connecting to it, and thankfully Atlas makes this rather easy. Installing the Node driver and connecting to your Atlas cluster Well, we stewed up this tutorial just for you and your loved ones, so read on. If you’ve made it this far, you’re probably building an app on top of MongoDB and want some help navigating your selectOnes, understanding projections, figuring out the difference(s) between insertMany and bulkWrite, and deciphering the loads of other methods they didn’t teach you in SQL class.
