# Optimize With MongoDB Atlas: Performance Advisor, Query Analyzer, and More

Optimizing MongoDB performance involves understanding the intricacies of your database's schema and queries, and navigating this landscape might seem daunting. There can be a lot to keep in mind, but MongoDB Atlas provides several tools to help spot areas where how you interact with your data can be improved.

In this tutorial, we're going to go through what some of these tools are, where to find them, and how we can use what they tell us to get the most out of our database. Whether you're a DBA, developer, or just a MongoDB enthusiast, our goal is to empower you with the knowledge to harness the full potential of your data.

## Identify schema anti-patterns
As your application grows and use cases evolve, potential problems can present themselves in what was once a well-designed schema. How can you spot these? Well, in Atlas, from the data explorer screen, select the collection you'd like to examine. Above the displayed documents, you'll see a tab called "Schema Anti-Patterns." 

Now, in my collection, I have a board that describes the tasks necessary for our next sprint, so my documents look something like this: 

```json
{
  "boardName": "Project Alpha",
  "boardId": "board123",
  "tasks": 
    {
      "taskId": "task001",
      "title": "Design Phase",
      "description": "Complete the initial design drafts.",
      "status": "In Progress",
      "assignedTo": ["user123", "user456"],
      "dueDate": "2024-02-15",
    },
    // 10,000 more tasks
  ]
}
```

While this worked fine when our project was small in scope, the lists of tasks necessary really grew out of control (relatable, I'm sure). Let's pop over to our schema anti-pattern tab and see what it says.

![Collection schema anti-pattern page][1]

From here, you'll be provided with a list of anti-patterns detected in your database and some potential fixes. If we click the "Avoid using unbounded arrays in documents" item, we can learn a little more.

![Collection schema anti-pattern page, dropdown for more info.][2]

This collection has a few problems. Inside my documents, I have a substantial array. Large arrays can cause multiple issues, from exceeding the limit size on documents (16 MB) to degrading the performance of indexes as the arrays grow in size. Now that I have identified this, I can click "Learn How to Fix This Issue" to be taken to the [MongoDB documentation. In this case, the solution mentioned is referencing. This involves storing the tasks in a separate collection and having a field to indicate what board they belong to. This will solve my issue of the unbounded array.

Now, every application is unique, and thus, how you use MongoDB to leverage your data will be equally unique. There is rarely one right answer for how to model your data with MongoDB, but with this tool, you are able to see what is slowing down your database and what you might consider changing — from unused indexes that are increasing your write operation times to over-reliance on the expensive `$lookup` operation, when embedded documents would do. 

## Performance Advisor
While you continue to use your MongoDB database, performance should always be at the back of your mind. Slow performance can hamper the user's experience with your application and can sometimes even make it unusable. With larger datasets and complex operations, these slow operations can become harder to avoid without conscious effort. The Performance Advisor provides a holistic view of your cluster, and as the name suggests, can help identify and solve the performance issues.

The Performance Advisor is a tool available for M10+ clusters and serverless instances. It monitors queries that MongoDB considers slow, based on how long operations on your cluster typically take. When you open up your cluster in MongoDB Atlas, you'll see a tab called "Performance Advisor."

, we have a database containing information on New York City taxi rides. A typical query on the application would look something like this:

```shell
db.yellow.find({ "dropoff_datetime": "2014-06-19 21:45:00",
                 "passenger_count": 1,
                 "trip_distance": {"$gt": 3 }
               })
```

With a large enough collection, running queries on specific field data will generate potentially slow operations without properly indexed collections. If we look at suggested indexes, we're presented with this screen, displaying the indexes we may want to create.

.

 or to our Developer Community Forums to see what other people are building.

  [1]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blta5008804d2f3ad0e/65b8cf0893cdf11de27cafc1/image3.png
  [2]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt7fc9b26b8e7b5dcb/65b8cf077d4ae74bf4980919/image1.png
  [3]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/bltcae2445ee8c4e5b1/65b8cf085f12eda542e220d7/image4.png
  [4]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt3cddcbae41a303f4/65b8cf087d4ae7e2ee98091d/image5.png
  [5]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt4ca5dd956a10c74c/65b8cf0830d47e0c7f5222f7/image7.png
  [6]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt07b872aa93e325e8/65b8cf0855a88a1fc1da7053/image6.png
  [7]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt64042035d566596c/65b8cf088fc5c08d430bcb76/image2.png