Use MongoDB from CLI (Bite-size article)
Tags: mongodb, cli, beginners
Published: 2023-09-10 00:19:06

#Intro
In this article, I will write about how to access your **MongoDB** account (Atlas) from **CLI**.

Typically, to manage the things on MongoDB account, I believe that many people would use a **web browser**, an editor **extension** (like VSCODE), or **MongoDB Compass** (GUI).

Most people around me typically manage things using the methods mentioned above, but I recently discovered the option of using CLI. I believe this method is quite common as well, but I personally only found it recently!

I'm sure that this CLI way make your coding journey more fun.
In this article, as an introduction, I will explain the process of accessing your MongoDB account only (so this article is quite short).

In this article, as an introduction, I will explain the process of accessing your MongoDB account only (so this article is quite short).

🌿 For this article, the prerequisite is that you already have a MongoDB account (Atlas). To better understand the process of the article, I recommend that you read the article after creating a MongoDB account and a cluster. 💻

🙇‍♂️ Sorry for Window lovers, but this article is for Mac user... 🍎

#Install mongodb-atlas-cli
To check the contents of a MongoDB Atlas cluster with the CLI, you can use the MongoDB Atlas CLI (**mongocli**). First thing first, let's look at the execution procedure.

We will use it by **Homebrew**, so please get it in advance if you don't have it in your computer yet.

Run below codes on Terminal:

```shell
brew install mongodb-atlas-cli
```

And then, let's check the version of it.

```shell
mongocli --version 
```

If you can see the version, that means the installation was successfully done!

##Tip: 'mongodb-atlas-cli' or 'mongocli'?

It’s a minor detail, but have you noticed that despite installing it with the 'mongodb-atlas-cli' command, subsequent operations (like version checks) are actually named 'mongocli'?

 This is because the MongoDB Atlas CLI is provided under the 'mongocli' command, and that's the official command name.

So, it's standard practice to use 'mongocli' instead of 'mongodb-atlas-cli' (I initially found it a bit confusing).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qqcvleep40xilpqoksls.png)


#Verification and Check

At this point, the CLI configuration is just in, so your account needs to be tied to it. So, run the following code.

```shell
mongocli auth login
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bcx3tiri7oslfoz8ci4b.png)


If it works properly, then web browser will open and you will see a screen where you can enter the Verification Code. Simply enter the code displayed in the CLI.

---

For one particular aspect here, I'd like to apologize.

While I was setting up my account like above, I recall performing some operations related to Atlas, such as configuring user settings and authentication, in addition to the login procedure mentioned in this guide. However, I didn't take any notes, so I've forgotten the specific steps I took 😅

If you encounter any discrepancies with the procedures outlined here, please adjust your approach accordingly.

---

Anyways, after the process finished successfully, you will see the message 'Successfully logged in as "_your email address_"' in the Terminal. And you will be asked which of your MongoDB projects you want to use as default.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2v3wvcpb4mhix7c2lv8.png)

Now you can see your projects in MongoDB from the CLI screen. And that means you have successfully connected to your account.

#Outro


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6fjgkwkfimh34wraf6c9.png)



After connecting to CLI, you will be able to do various operations, such as checking and editing the details of the information in your MongoDB account.

I wanted to write more about this, but I didn't have much time today, sorry!

I may write more about this topic in the future - when I come up with ideas, so please stay tuned.

Thank you for reading, happy coding!