Lesson 1: MongoDB Logs in Atlas / Learn

Video Transcript (English)

In this video, you’ll learn how to download logs in MongoDB Atlas.

First, you’ll learn how to check that you have the necessary access permissions to download logs in Atlas. Then we’ll go through an example of downloading logs by using both the Atlas UI and Atlas CLI. Finally, we’ll extract the archived file. Let’s get started!

To download logs from an Atlas cluster, you must have the “Project Data Access Read Only" role or greater. In the Atlas CLI, this role is also referred to as `group-data-access-read-only`. This feature is only available for M10-or-above Atlas clusters.

The easiest way to check if we have this permission is to go to the Database Deployments dashboard in Atlas.

First, we make sure that the correct organization and project are selected. Then, next to the name of the project, we click here – and select “Project Settings”.

From the left-hand menu, we select Access Manager and locate our name in the list. We see the “Project-Data Access-Read-Only" role, so we’re all set! If you do not see this role, be sure to reach out to the organization owner or project creator to request access.

We can also use the Atlas CLI to determine the roles of each member of our project.

To do this, we run `atlas project users list` with the dash “O” JSON option. We include this option because it will provide the information we’re looking for, the roles of each member, rather than just a list of usernames and IDs.

The output is a list of all members of the project and their roles. The roles are listed by their API names. The one we’re looking for is `Group-Data-Access-Read-Only` for downloading logs.

We see this role listed here, so we’re all set.

We’ve just verified that we have the correct role for downloading logs. Now, let’s imagine our primary node went down, and we wanted to find clues as to what happened. In the event of a failover, we could download logs from the secondary, which will include the events leading up to the failover from the perspective of this secondary node. Let’s download some logs from a secondary node on an M10 Atlas cluster.

First we’ll do this by using the Atlas UI. We’re signed into Atlas, so now we’ll locate the name of the cluster that we want to download logs for. We click here, and select Download Logs.

Here, we can select the server and time. If the cluster has other features enabled, such as the audit log, they will be listed here as well. We will select the secondary node to download logs from, and then download the logs.

The resulting download will be a compressed archive that contains the `mongod.log` file along with any other items you selected.

Now that we’ve used the Atlas UI, let’s download the logs by using the Atlas CLI.

To do this, we use the `atlas logs download` command. This command accepts a hostname and the name of the log file you want to download.

We’ll provide the hostname for the primary node of our replica set, and the filename, which for MongoDB logs is `mongodb.gz`.

We can also provide options such as the start and end date. A full list of options can be found in the Atlas CLI docs.

We run the command to download the logs. Once it’s downloaded, we can extract the log file from the archive and use it.

Nice work!

In this video, you learned how to check that you have the necessary access permissions to download logs from an Atlas cluster. We also went through the process of downloading logs by using both the Atlas UI and Atlas CLI. Finally, we extracted the log file.