Dragonfly Cloud announces new enterprise security features - learn more

Dragonfly

Question: What are MongoDB global clusters?

Answer

MongoDB global clusters refer to a configuration in MongoDB Atlas that allows for the deployment of a single database across multiple geographical locations or regions. This capability is particularly valuable for applications that require global data presence to reduce latency for users distributed around the world or to comply with data sovereignty regulations.

Key Features

How to Configure

To set up a global cluster in MongoDB Atlas, follow these general steps:

  1. Create an Atlas Account and Cluster: If you haven't already, sign up for MongoDB Atlas and create a cluster. Choose a cloud provider and a region that supports Global Clusters.
  2. Enable Global Writes: In the cluster configuration options, find and enable the 'Global Writes' feature.
  3. Configure your Regions: Select the regions where you want your data to be replicated. You can define a default write region and additional read regions.
  4. Define Location-Based Rules: Using custom sharding keys, you can specify rules for how data is distributed globally. These rules determine where documents are stored based on fields within those documents.
  5. Deploy your Application: Once your global cluster is configured, deploy your application. Ensure that your application's connection string points to the global cluster to take advantage of the distributed nature.
// Example of connecting to a MongoDB global cluster using the MongoDB Node.js driver
const { MongoClient } = require('mongodb');

const uri = 'your_mongodb_atlas_global_cluster_uri';
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });

async function run() {
    try {
        await client.connect();
        console.log('Connected successfully to global cluster');
        // Perform operations
    } finally {
        await client.close();
    }
}
run().catch(console.dir);

Considerations

MongoDB Atlas' global clusters feature simplifies setting up and managing a globally distributed database, enabling applications to provide better user experiences worldwide while addressing compliance needs.

Was this content helpful?

Other Common MongoDB Performance Questions (and Answers)

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost