> ## Documentation Index
> Fetch the complete documentation index at: https://docs.appsignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MongoDB instrumentation

export const VersionRequirements = ({versions = []}) => {
  if (!Array.isArray(versions) || versions.length === 0) {
    return null;
  }
  const boundaries = {
    upper: " or lower",
    exact: "",
    lower: " or higher"
  };
  const containerStyle = {
    marginTop: "0.5rem",
    marginBottom: "1.5rem"
  };
  const lineStyle = {
    display: "block",
    margin: "0 0 0.35rem 0",
    fontSize: "0.875rem",
    lineHeight: "1.4"
  };
  const pillBaseStyle = {
    display: "inline-block",
    padding: "0.1em 0.4em",
    borderRadius: "0.25rem",
    border: "1px solid",
    fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace",
    fontSize: "0.85em",
    fontWeight: 500
  };
  const pillColors = {
    "AppSignal for Elixir": {
      background: "#f3e8ff",
      borderColor: "#e9d5ff",
      color: "#9333ea"
    },
    "AppSignal for Front-end": {
      background: "#fef9c3",
      borderColor: "#fde68a",
      color: "#ca8a04"
    },
    "AppSignal for Go": {
      background: "#ccfbf1",
      borderColor: "#99f6e4",
      color: "#0d9488"
    },
    "AppSignal for JavaScript": {
      background: "#fef9c3",
      borderColor: "#fde68a",
      color: "#ca8a04"
    },
    "AppSignal for Node.js": {
      background: "#dcfce7",
      borderColor: "#bbf7d0",
      color: "#16a34a"
    },
    "AppSignal for Python": {
      background: "#dbeafe",
      borderColor: "#bfdbfe",
      color: "#2563eb"
    },
    "AppSignal for Ruby": {
      background: "#fee2e2",
      borderColor: "#fecaca",
      color: "#dc2626"
    },
    "AppSignal for Rust": {
      background: "#ffedd5",
      borderColor: "#fed7aa",
      color: "#ea580c"
    }
  };
  const defaultPillColor = {
    background: "#f4f4f5",
    borderColor: "#e4e4e7",
    color: "#52525b"
  };
  const getPillStyle = name => ({
    ...pillBaseStyle,
    ...pillColors[name] || defaultPillColor
  });
  const getBoundText = bound => {
    return boundaries[bound] || boundaries.lower;
  };
  return <div style={containerStyle}>
      {versions.map((v, i) => <p key={`${v.name}-${v.version}-${v.bound || "lower"}-${i}`} style={lineStyle}>
          This feature requires{" "}
          <code style={getPillStyle(v.name)}>{v.name}</code> version {v.version}
          {getBoundText(v.bound)}.
        </p>)}
    </div>;
};

<VersionRequirements
  versions={[
{ name: "AppSignal for Ruby", version: "1.0" }
]}
/>

The [Mongoid] gem relies on the [Mongo Ruby Driver]. AppSignal activates Mongo Ruby Driver instrumentation automatically if it is detected in the project.

AppSignal's MongoDB instrumentation supports the [Mongo Ruby Driver] gem and the [Mongoid] gem out-of-the-box; no manual setup is required. When AppSignal detects MongoDB metrics, it will create an [Magic Dashboard](#magic-dashboard), allowing you to monitor core metrics visually.

## Performance monitoring

Once AppSignal begins reporting MongoDB metrics, AppSignal will give you performance insights via:

* [Event timeline](#event-timeline)
* [Sample breakdown](#sample-breakdown)
* [Slow queries](#slow-queries)

### Event timeline

The event timeline gives you deep insights into MongoDB query performance, allowing you to see exactly what queries are run, when, and what impact they're having on your application's responsiveness.

<img src="https://mintcdn.com/appsignal-715f5a51/4TRZP0Sq9Zq7PAPW/assets/images/screenshots/ruby/integrations/mongodb/event-timeline.png?fit=max&auto=format&n=4TRZP0Sq9Zq7PAPW&q=85&s=f3f8e02b4125bccc426dc388631ae24a" alt="Example MongoDB event timeline" width="1314" height="680" data-path="assets/images/screenshots/ruby/integrations/mongodb/event-timeline.png" />

### Sample breakdown

Sample breakdowns allow you to review MongoDB performance at a glance, allowing you to quickly spot performance problems without having to dive deep into the details.

<img src="https://mintcdn.com/appsignal-715f5a51/4TRZP0Sq9Zq7PAPW/assets/images/screenshots/ruby/integrations/mongodb/sample-breakdown.png?fit=max&auto=format&n=4TRZP0Sq9Zq7PAPW&q=85&s=43404cce6c91f5d9162541884e9a1766" alt="Example MongoDB performance sample" width="1310" height="430" data-path="assets/images/screenshots/ruby/integrations/mongodb/sample-breakdown.png" />

### Slow queries

AppSignal has a whole suite of tools aimed at helping you improve your application's performance. Slow queries is a simple and informative overview of your application's slow queries and the impact they're having on your application's performance, allowing you to quickly and confidently decide on the steps needed to optimize them.

<img src="https://mintcdn.com/appsignal-715f5a51/4TRZP0Sq9Zq7PAPW/assets/images/screenshots/ruby/integrations/mongodb/slow-queries.png?fit=max&auto=format&n=4TRZP0Sq9Zq7PAPW&q=85&s=b08cf67361773c2cb5b900d8be3e6255" alt="Example of AppSignal slow queries feature" width="2050" height="1030" data-path="assets/images/screenshots/ruby/integrations/mongodb/slow-queries.png" />

## Magic dashboard

When AppSignal receives MongoDB metrics, it will create a MongoDB magic dashboard, available from the dashboard section of the AppSignal app.

The MongoDB magic dashboard will have the following graphs:

| Graph                                   | Metrics                  | Tags       |
| --------------------------------------- | ------------------------ | ---------- |
| [Throughput](#throughput-graph)         | `mongodb_query_duration` | `database` |
| [Query duration](#query-duration-graph) | `mongodb_query_duration` | `database` |

Tags give you a contextual breakdown of Active job performance information currently AppSignal reports the following tags for Active Job jobs:

| Name       | Description                                    |
| ---------- | ---------------------------------------------- |
| `database` | Name of database metric data is recorded from. |

Each tag will be represented with a colored line on the graph:

<img src="https://mintcdn.com/appsignal-715f5a51/4TRZP0Sq9Zq7PAPW/assets/images/screenshots/ruby/integrations/mongodb/dashboard.png?fit=max&auto=format&n=4TRZP0Sq9Zq7PAPW&q=85&s=c1765eeec6ec674e68749b07af56a796" alt="Example MongoDB dashboard" width="1432" height="672" data-path="assets/images/screenshots/ruby/integrations/mongodb/dashboard.png" />

### Throughput graph

The Throughput graph shows the amount of queries executed on each MongoDB database.

You can use this graph to understand how many queries your app's databases are handling, spot inefficient queries, and potential n+1 and scaling problems.

### Query duration graph

The Query duration graph shows the 95th percentile and average duration of the queries executed on each MongoDB database.

You can use this graph to understand the performance of database queries, pinpoint performance issues, and fine-tune slow queries.

[Mongoid]: https://github.com/mongodb/mongoid

[Mongo Ruby Driver]: https://github.com/mongodb/mongo-ruby-driver
