---
title: "MongoDB® - Connect with MongoDB Compass"
description: "Learn how to connect to a MongoDB® database instance with one of the world's most famous Open Source (SSPL) management tools for MongoDB®: MongoDB Compass."
url: https://docs.us.ovhcloud.com/en/public-cloud/databases/mongodb-connect-mongodb-compass
lang: en
---
> For AI agents: the complete documentation index is available at https://docs.us.ovhcloud.com/en/llms.txt, the full documentation bundle is available at https://docs.us.ovhcloud.com/en/llms-full.txt.

# MongoDB® - Connect with MongoDB Compass

**Learn how to connect to a MongoDB® database instance with one of the world's most famous Open Source (SSPL) management tools for MongoDB®: MongoDB Compass.**

Cloud Databases allow you to focus on building and deploying cloud applications while OVHcloud takes care of the database infrastructure and maintenance in operational conditions.

 

## Requirements

- A [Public Cloud project](https://us.ovhcloud.com/public-cloud/) in your OVHcloud account
- Access to the [OVHcloud Control Panel](https://manager.us.ovhcloud.com/#/hub)
- A MongoDB[®](#go-further) database running on your OVHcloud Cloud Databases ([this guide](https://docs.us.ovhcloud.com/en/public-cloud/databases/getting-started.md) can help you to meet this requirement)
- [Configure your MongoDB® instance](https://docs.us.ovhcloud.com/en/public-cloud/databases/mongodb-configure-instance-accept-incoming-connections.md) to accept incoming connections
- A MongoDB® Compass stable version installed and public network connectivity (Internet)

**Note:**

This guide was made in MongoDB® Compass version 1.30.1.

 

## Concept

A MongoDB® instance can be managed in multiple ways. One of the easiest and most powerful is to use a Command Line Interface (CLI), as shown in our guide: [Connect to MongoDB® with CLI](https://docs.us.ovhcloud.com/en/public-cloud/databases/mongodb-connect-cli.md) or by using programming languages, such as [PHP](https://docs.us.ovhcloud.com/en/public-cloud/databases/mongodb-connect-php.md) or [Python](https://docs.us.ovhcloud.com/en/public-cloud/databases/mongodb-connect-python.md).

Another way is to interact directly using a management tool for MongoDB®: MongoDB® Compass.

To do so, we will need to install MongoDB® Compass, configure our Cloud Databases for MongoDB® instances to accept incoming connections, and finally configure MongoDB®.

 

## Instructions

### Installation

Please follow the [official documentation](https://docs.mongodb.com/compass/current/install/) to install MongoDB® Compass.

We are now ready to learn how to connect to our MongoDB® instance.

 

### Connect with MongoDB® Compass

In MongoDB® Compass, fill in the **URI** field with your service URI and click `Connect`:

Now you can interact with your Cloud Databases for MongoDB®:

 

### Insert and Query Data

You can use the [mongoshell](https://www.mongodb.com/docs/mongodb-shell/), integrated into Compass, to create your first database and collection. Below is a script that creates the database **company** and collection **customer** and inserts 100 random documents.

#### Load Data into MongoDB®

To load 100 documents into a collection called `customer` with random data, use the following `mongosh` script:

```javascript
use company;

// Function to generate random data
function getRandomData() {
    const firstNames = ["John", "Jane", "Mary", "Michael", "Sarah", "Robert", "Linda", "James", "Patricia", "David"];
    const lastNames = ["Smith", "Johnson", "Williams", "Jones", "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor"];
    const domains = ["example.com", "email.com", "mail.com", "test.com", "demo.com"];

    function getRandomItem(array) {
        return array[Math.floor(Math.random() * array.length)];
    }

    return {
        firstName: getRandomItem(firstNames),
        lastName: getRandomItem(lastNames),
        email: `${getRandomItem(firstNames).toLowerCase()}.${getRandomItem(lastNames).toLowerCase()}@${getRandomItem(domains)}`,
        age: Math.floor(Math.random() * 60) + 18,
        createdAt: new Date()
    };
}

// Insert 100 random documents into the customer collection
const bulk = db.customer.initializeUnorderedBulkOp();
for (let i = 0; i < 100; i++) {
    bulk.insert(getRandomData());
}
bulk.execute();

print("100 random documents inserted into the 'customer' collection.");
```

 

#### Query Data with the Aggregation Framework

The MongoDB® aggregation pipeline below uses the [MongoDB® Aggregation Framework](https://www.mongodb.com/docs/manual/aggregation/) to group customers by age and count each occurrence. You can use the mongoshell to execute:

```javascript
db.customer.aggregate([
    {
        $group: {
            _id: "$age",
            count: { $sum: 1 }
        }
    },
    {
        $sort: { _id: 1 }
    }
]);
```

You can also use the UI with Compass to execute the aggregation pipeline.

 

## Go further

Visit the [GitHub examples repository](https://github.com/ovh/public-cloud-databases-examples/tree/main/databases/mongodb) to find out how to connect to your database in several languages.

Browse all the [Databases guides](https://docs.us.ovhcloud.com/en/public-cloud/databases/landing-page-databases.md).

Browse the rest of the [OVHcloud US documentation](https://docs.us.ovhcloud.com/en/index.md) for guides on our other products and services.

Learn more about [Managed Databases](https://us.ovhcloud.com/public-cloud/databases/) on the OVHcloud US website.

If you need training or technical assistance to implement our solutions, contact your sales representative or click on [this link](https://us.ovhcloud.com/professional-services/) to get a quote and ask our Professional Services experts for a custom analysis of your project.

OVHcloud Managed Databases and Analytics:

- Grafana® is a registered trademark of Grafana Labs and is used with the permission of Grafana Labs. OVH SAS and its subsidiaries are not affiliated with or endorsed by Grafana Labs.
- Kafka® is a registered trademark of The Apache Software Foundation and has been licensed for use by OVHcloud, who has no affiliation with and is not endorsed by The Apache Software Foundation.
- MongoDB® is a registered trademark of MongoDB, Inc.
- MySQL® is a registered trademark of Oracle and/or its affiliates.
- PostgreSQL® is a registered trademark of the PostgreSQL Community Association of Canada.
