Navigation

stitch-cli

The MongoDB Stitch Command Line Interface (stitch-cli) allows you to programmatically manage your MongoDB Stitch applications. With stitch-cli, you can create or update Stitch applications from a local directory as well as export existing applications to a local directory.

Installation

The easiest way to install stitch-cli is with the npm package manager. Ensure that you have Node.js installed, then run the following command in your shell:

npm install -g mongodb-stitch-cli

You can also install the CLI from npm with Yarn:

yarn global add mongodb-stitch-cli
1

Download the stitch-cli binary

You can download the stitch-cli binary directly from the Stitch UI.

  1. Navigate to the Settings page from the left-hand navigation.
  2. Select the Export tab.
  3. In the Download CLI Client section, select the operating system on which you want to install stitch-cli. The CLI binary should begin downloading immediately.
2

Add the stitch-cli binary to your system PATH

When you call stitch-cli from the command line, your shell searches each directory listed in your PATH environment variable for the stitch-cli executable binary.

Move the stitch-cli binary file from your downloads folder to a directory listed in your PATH.

mv /path/to/downloads/stitch-cli /usr/local/bin/stitch-cli

You can check which directories are listed in your PATH by running the following from the command line:

echo $PATH

To add a directory to your path, add the following to the bottom of your shell rc file (e.g. ~/.bashrc), substituting in the path of the directory you’d like to add:

export PATH=${PATH}:path/to/directory

When you call stitch-cli.exe from the command line, your system searches each directory listed in your %PATH% environment variable for the stitch-cli executable file.

Move stitch-cli.exe to a directory that is listed in %PATH%.

You can check which directories are listed in %PATH% as well as add new directories from the Environment Variables configuration window. You can find this window by searching for “Environment Variables” or by following these steps:

  1. Depending on which version of Windows you’re running, right click My Computer or This PC and select Properties.
  2. Click Advanced Properties, then Environment Variables.

In the Environment Variables window, your PATH variable is listed under System Variables.

3

(Linux / macOS) Configure execution permissions for stitch-cli

On Linux and Mac systems, no user has execution permissions for stitch-cli by default. To add execution permissions, run the following command:

chmod +x path/to/stitch-cli

To confirm that stitch-cli has execution permissions, navigate to the directory containing the binary and run the following command:

ls -l | grep "stitch-cli"

The output of this command should resemble the following:

-rwxrwxr-x@  1 user  staff      9443152 Mar  6 12:01 stitch-cli

The ls -l command lists the file’s permissions followed by some additional information. If the permissions string in your output includes the letter x then you have successfully configured execution permissions. If no x is present (e.g. -rw-r--r--@) you did not successfully configure execution permissions and should run the chmod command as described above.

CLI Reference

General Options

stitch-cli

The following options are available for all stitch-cli commands:

--disable-color
Optional.

Suppress all text color in stitch-cli output.

By default, some output such as errors and import diffs are colorized. Use this flag if you wish to prevent this behavior.

Import an Application

stitch-cli import

Use stitch-cli import to import a local application directory into a hosted Stitch application. If you import a directory into an application that doesn’t exist, stitch-cli can create the application for you.

stitch-cli import \
  --app-id=myStitchApp-abcde \
  --path=./path/to/app/dir \
  --strategy=merge
--app-id <MongoDB Stitch Application ID>
Optional.

The Application ID of your MongoDB Stitch application.

If not specified, stitch-cli will attempt to use the value of app_id defined in stitch.json. If stitch.json does not have an app_id value, stitch-cli will ask if you’d like to create a new application.

--path <path>
Optional.

The path to the directory containing files you wish to import. The directory must contain, at minimum, a valid stitch.json file.

If the path argument is omitted, stitch-cli will search for a stitch.json file in the current application directory.

--strategy ['merge|replace']
Optional.
Default: Merge

The import strategy that stitch-cli should use when reconciling imported entities.

--project-id
Optional.

The Project ID of the Atlas project on which you want to host a newly created Stitch application. If specified, stitch-cli will not prompt you to select a project when creating a new app.

Note

stitch-cli ignores the value of --project-id unless you are importing a new application.

Export an Application

stitch-cli export

Use stitch-cli export to save a Stitch application configuration to a local application directory.

stitch-cli export \
  --app-id=myStitchApp-abcde \
  --output=path/to/exported/app/dir
--app-id <MongoDB Stitch Application ID>
Optional.

The Application ID of your MongoDB Stitch application.

--output <path>
Optional.

The path of the directory where Stitch will export your application.

If specifiied, stitch-cli creates a directory at the given path and exports the application configuration into the new directory. If a file or directory already exists at the specified path, the export will fail.

Note

If the output argument is omitted, stitch-cli will export the application configuration to a new directory within the current working directory.

--as-template
Optional.

If enabled, stitch-cli exports the application configuration without any service ID values, including the App ID. This simplifies the creation of new applications from an exported configuration.

Authenticate a CLI User

stitch-cli login

Use stitch-cli login to authenticate a MongoDB Cloud user with a MongoDB Atlas API Key.

stitch-cli login --username=cloud.username@example.com --api-key=my-api-key
--username <MongoDB Cloud username>

The username of the MongoDB Cloud account you wish to log in with.

--api-key <api key>

A valid MongoDB Atlas API Key for the MongoDB Cloud account you wish to log in with.

Log Out the Current CLI User

stitch-cli logout

Use stitch-cli logout to log out the currently logged in user.

stitch-cli logout