Export an App
On this page
Overview
You can download a directory of your App's configuration files by exporting them. This allows you to save your App's configuration in source control and to work locally with App Services CLI and your preferred text editor.
The exported directory contains configuration files for most components of your App, including Data Sources, Functions, Triggers, and other services. For more information on the contents of an exported App, see App Configuration.
The export does not include any Secrets. If you create a new App based on exported configuration files, you must manually add Secrets to the new App. For more information, see Copy an App.
Before You Begin
You will need the following to export an App in the Atlas UI:
A MongoDB Atlas account with Project Owner permissions. To learn how to sign up for a free account, see Get Started with Atlas.
You will need the following to export an App in the CLI:
A MongoDB Atlas account with Project Owner permissions. To learn how to sign up for a free account, see Get Started with Atlas.
A MongoDB Atlas Admin API public/private key pair. The API key must have Project Owner permissions to work with App Services Admin API.
A copy of App Services CLI installed and added to your local system
PATH
. To learn how, see Install App Services CLI.Your App's client App ID. This is the unique string that contains your App name, e.g.
"myapp-abcde"
. To learn how to find your App ID, see Get App Metadata.
You will need the following to export an App with the Admin API:
A MongoDB Atlas account with Project Owner permissions. To learn how to sign up for a free account, see Get Started with Atlas.
A MongoDB Atlas Admin API public/private key pair. The API key must have Project Owner permissions to work with App Services Admin API.
Your App's internal ObjectId hex string and the Project ID of the Atlas Project that contains your App. To learn how to find these, see Get App Metadata.
Procedure
Export the App
Click Deployment in the left-hand navigation.
From here, there are two ways to export your app:
- To export your App's current configuration, click the
- Export App tab, then click the Export App button.
- To export your App's configuration from a previous
deployment, click the History tab and find the deployment you want to export.
Once you've found the deployment, click the Export button at the end of the row.
Run the App Export Command
The pull
command downloads an application's
configuration files to a local directory. You choose which
app to export by specifying its Client App ID with the
--remote
flag.
appservices pull --remote=<Client App ID>
By default the command pulls files into the current working
directory. You can configure the command to create a new
directory instead by specifying the directory path with the
--local
flag.
appservices pull --remote=<App ID> --local=<Output Directory Path>
Tip
The directory specified by --local
must not already
exist, otherwise the CLI throws an error and does not
pull the configuration files.
The command also supports additional flags that you can optionally include to customize your app. The following table lists common flags you might use:
--include-dependencies | If specified, external dependencies are exported as a
node_modules archive in the /functions
directory. |
--include-hosting | If specified, hosted static assets are exported
in the /hosting/files directory. |
Authenticate a MongoDB Atlas User
Call the admin user authentication endpoint with your MongoDB Atlas API key pair:
curl -X POST \ https://services.cloud.mongodb.com/api/admin/v3.0/auth/providers/mongodb-cloud/login \ -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ -d '{ "username": "<Public API Key>", "apiKey": "<Private API Key>" }'
If authentication succeeds, the response body contains a JSON object
with an access_token
value:
{ "access_token": "<access_token>", "refresh_token": "<refresh_token>", "user_id": "<user_id>", "device_id": "<device_id>" }
The access_token
grants access to the App Services Admin API. You
must include it as a Bearer token in the Authorization
header for
all Admin API requests.
Export Your App
To export your App, send a request to the Export an App endpoint.
Make sure to include your Admin API access_token
, the
groupId
of the Atlas project containing your App, and
the App's internal appId
hex string:
curl -X GET \ https://services.cloud.mongodb.com/api/admin/v3.0/groups/{groupId}/apps/{appId}/export \ -H 'Authorization: Bearer <access_token>' \ -H 'Content-Type: application/json' \ --output ./exported-app.zip
You can export the configuration for a specific deployment
by specifying the deployment _id
as a URL query
parameter:
https://services.cloud.mongodb.com/api/admin/v3.0/groups/{groupId}/apps/{appId}/export?deployment={deploymentId}
If the request is successful, the endpoint returns a 200
response that contains a .zip
directory of your
application's current configuration files.
Output
An exported App contains configuration files for every component of the App. For detailed information about each type of configuration file, see App Configuration.
An exported configuration directory has the following structure:
app/ ├── root_config.json ├── auth/ │ ├── providers.json │ └── custom_user_data.json ├── data_sources/ │ └── <service name>/ │ ├── config.json │ └── <database>/ │ └── <collection>/ │ ├── schema.json │ └── rules.json ├── environments/ │ ├── no-environment.json │ ├── development.json │ ├── testing.json │ ├── qa.json │ └── production.json ├── functions/ │ ├── config.json │ ├── <function>.js │ └── <directory>/ │ └── <function>.js ├── graphql/ │ ├── config.json │ └── custom_resolvers │ └── <resolver name>.json ├── hosting/ │ ├── config.json │ ├── metadata.json │ └── files/ │ └── <files to host> ├── http_endpoints/ │ ├── config.json │ ├── data_api_config.json │ └── [Deprecated] <service name>/ │ ├── config.json │ └── incoming_webhooks/ │ ├── config.json │ └── source.js ├── log_forwarders/ │ └── <name>.json ├── sync/ │ └── config.json ├── triggers/ │ └── <trigger name>.json └── values/ └── <value name>.json