- Stitch >
- MongoDB Atlas >
- Configure MongoDB
Link a MongoDB Atlas Cluster¶
Overview¶
You can use Stitch to work with any MongoDB Atlas cluster associated with the same Atlas project as your Stitch application. To connect to a cluster through Stitch, you must first link it to a new MongoDB service in your application.
You can create a MongoDB service and link a cluster to your Stitch application through the Stitch UI or with an import/export configuration directory. Select the tab below that corresponds to the method you want to use.
Procedure¶
- Stitch UI
- Import/Export
Link a New Cluster¶
Click Link a Cluster and provide the following configuration information on the Cluster Configuration screen:
Field | Description |
---|---|
Atlas Cluster | A MongoDB Atlas cluster associated with the same project as your Stitch application. |
Stitch Service Name | A name for the Stitch service that connects to the cluster. You will use this name when referring to the cluster in other parts of your application, such as when you instantiate a MongoDB service client. Example Consider a MongoDB cluster with the Stitch
Service Name |
MongoDB Connection String | If enabled, you may connect to this cluster through Stitch over the wire protocol. You can also find a connection string that Stitch generates for you here. |
Save the Linked Cluster¶
Once you’ve selected and configured a MongoDB cluster, click Save.
Stitch will immediately begin the process of linking to the cluster, which could take up to five minutes. Once Stitch is finished linking to the cluster, you can start reading and writing data.
Export Your Stitch Application¶
To link a MongoDB Atlas cluster to your Stitch application with stitch-cli, you need a previously created application configuration.
You can export your application configuration from the Export tab of the Settings page in the Stitch UI, or by running the following command from an authenticated instance of stitch-cli:
Create a MongoDB Service Configuration Directory¶
Create a new subdirectory in the /services
folder of the
application directory that you exported. The name of the subdirectory
should match the name of the MongoDB service you’re creating.
Add a MongoDB Service Configuration File¶
Add a file named config.json
to the new service directory. The
configuration file should have the following form:
Configuration Value | Description |
---|---|
Service Name name
|
Required. The name of the MongoDB service. |
Atlas Cluster config.clusterName
|
Required. The name of the MongoDB Atlas cluster that you want to link to your application. |
MongoDB Connection String config.wireProtocolEnabled
|
Required. A boolean indicating whether Stitch should allow clients to connect to this cluster with a connection string over the wire protocol. |
Import the Application Directory¶
Once you’ve added the MongoDB service configuration, all that’s left is to import the function.
Ensure that
config.json
is saved.Navigate to the root of the exported application directory.
Log in to MongoDB Atlas with
stitch-cli
:Import the directory:
Stitch will immediately begin the process of linking to the cluster, which could take up to five minutes. Once Stitch is finished linking to the cluster, you can begin working with it immediately.