Another Way: A Free Cluster on MongoDB Atlas

Make a free MongoDB Atlas cluster in the browser, with a database user and your IP address on its access list, connect mongosh and Compass to it with its mongodb+srv connection string, and stay on the Free tier so nothing costs money.

Novice · MongoDB · Database · Updated

By

After this lesson you can

  • Put the steps of making a free Atlas cluster in order, from the account to the connection string, and say what would cost money
  • Read an Atlas connection string, which starts mongodb+srv, tell it from a local one, and keep its password out of files you share

Key takeaways

  • MongoDB Atlas runs MongoDB for you in the cloud. A cluster is Atlas's word for one MongoDB it runs for you.
  • The Free cluster has 512 MB of storage, is free forever and is one per project. Atlas pauses it after 30 days with no connections, and you can resume it.
  • The steps are an account, a Free cluster, a database user with a password, your IP address on the access list, then the connection string.
  • An Atlas connection string starts mongodb+srv and names your cluster, where a local one is mongodb://localhost:27017.
  • Choose only Free. The other cluster types cost money, and nothing in this course needs them.

Maybe your laptop belongs to a school or an employer and won't let you install programs, or you'd like your data reachable from any computer you sit down at. MongoDB Atlas runs MongoDB for you in the cloud, and it has a free option that's enough for every lesson in this course. Choose this lesson instead of Setup: MongoDB, mongosh and Compass, or as well as it. It takes about fifteen minutes and an email address.

MongoDB that someone else runs

Keeping photos on your own computer means you look after the disk; keeping them in cloud storage means someone else does, and you reach them through the internet. Atlas is the second kind, for MongoDB. A cluster is Atlas's word for a MongoDB it runs for you: a small group of servers in a data center that keep your data, with copies, and answer your queries.

The Free cluster has 512 MB of storage, many times what this course's data needs. It's free forever, and you can have one in each Atlas project. If nothing connects to it for 30 days, Atlas pauses it, and you can resume it whenever you like.

What costs money, and how to avoid it

Atlas also offers clusters that cost money (on its screens, Flex and Dedicated). This course never needs one. Choose Free when you create the cluster, and never scale it up to another type later.

MongoDB's guide to the free cluster doesn't mention a payment card. If any screen asks for card details, stop there: nothing in this course needs a paid cluster, and the local install in Setup: MongoDB, mongosh and Compass is free too.

Make your free cluster

  1. Sign up. Go to mongodb.com/atlas and sign up with an email address, a Google account or a GitHub account (GitHub sign-up needs a public email address on your GitHub profile). Atlas makes an organization and a project for you: folders that hold your clusters. Answer any welcome questions it asks.
  2. Create the cluster. On your project's Overview page, click Create. Choose Free (some screens call it M0). Pick any provider (AWS, Google Cloud or Azure) and a region near you, type a name in the Name box, such as sunday-kitchen, and click Create. A cluster's name can't be changed later. The cluster is ready within seconds, and the Security Quickstart opens.
  3. Make a database user. Type a Username and a Password, or copy the strong one Atlas suggests and keep it in a password manager, then click Create Database User. This isn't your Atlas sign-in: it's the name and password that programs, mongosh and Compass use to reach your data.
  4. Let your computer in. Click Add My Current IP Address, then Finish and Close, then Go to Overview. An IP address is your internet connection's address. The cluster's IP access list works like a guest list: only addresses on it can connect. On a different network, such as a library's Wi-Fi, you add that address too.

Atlas's page for creating a cluster, with the Free option chosen, a provider and region picked, and the name sunday-kitchen typed in the Name box above the Create button

Connect mongosh and Compass

On your project's Clusters page, click Connect beside your cluster, choose Shell, then pick mongosh. Atlas shows a command that starts mongosh and holds your cluster's address and your database user's name. Copy it, paste it into VS Code's terminal, press Enter, and type your database user's password when the shell asks for it. You land at the same kind of prompt as with a local install, and every query in this course works the same way.

For Compass, click Connect again, choose Compass, and copy the string it shows. Where the string has a placeholder for the password, in angle brackets, put your database user's password in its place. Looking Around in Compass shows where to paste it.

Atlas's Connect window with Shell chosen and mongosh picked, showing the mongosh command to copy, with the cluster's address and the user name hidden

The exercises' tests never use your Atlas cluster: they start a throwaway MongoDB of their own on your computer. Without MongoDB installed, the first npm test downloads one for the tests, about 950 MB on Windows and about 180 MB on a Mac, once per computer. Plan that first run for a fast connection.

Reading the connection string

Both commands hold a connection string: everything a program needs to reach a MongoDB, in one line. An Atlas one has this shape, with your own cluster's address in place of the part in angle brackets:

mongodb+srv://<cluster-address>.mongodb.net/

Compare it with the local one from Setup: MongoDB, mongosh and Compass:

Connection string Where the MongoDB is
mongodb://localhost:27017 On this computer, at port 27017
mongodb+srv://<cluster-address>.mongodb.net/ On Atlas: +srv means "look up this cluster's servers by its name"

A connection string with your password in it is a key to your data. Keep it out of anything you share: a file you push to GitHub, a screenshot, a message asking for help.

Check yourself

2 questions to try on the lesson page.

So what

A free Atlas cluster gives you a MongoDB you can reach from anywhere, at no cost, as long as you stay on Free and keep its connection string to yourself.

Key terms

Related