Navigation

stitch-cli

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

Installation

1

Download the stitch-cli binary

In the Stitch UI, navigate to the Export page and select the binary for your operating system in the Download CLI Client section.

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 options in this section are available across 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

stitch-cli import
stitch-cli import \
  --app-id=myStitchApp-abcde \
  --path=./path/to/app/dir \
  --strategy=merge

Description

Import a new application or update an existing application from a local directory.

Arguments

--app-id <MongoDB Stitch Application ID>

Optional.

The Application ID of your MongoDB Stitch application.

If no app-id value is specified, stitch-cli will attempt to use the value of app_id defined in stitch.json. If app_id is not defined, 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.

If the path argument is omitted, stitch-cli will attempt to import the current working directory.

--strategy ['merge|replace']

Default: merge

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

export

stitch-cli export
stitch-cli export \
  --app-id=myStitchApp-abcde \
  --output=path/to/exported/app/dir

Description

Export a Stitch application to a local directory.

Arguments

--app-id <MongoDB Stitch Application ID>

The Application ID of your MongoDB Stitch application.

--output <path>

Optional. The path of the directory your application will be exported to.

If the output argument is omitted, stitch-cli will output your application to a directory with the same name as the application in the current working directory.

login

stitch-cli login
stitch-cli login --username=cloud.username --api-key=my-api-key

Description

Authenticate a MongoDB Cloud user with a MongoDB Atlas API Key.

Arguments

--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 username you wish to log in with.

logout

stitch-cli logout
stitch-cli logout

Description

Deauthenticate the currently logged in user.