- Stitch >
- Application Deployment >
- Reference
Stitch CLI¶
On this page
Overview¶
-
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¶
- npm / Yarn
- Manual Install
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:
You can also install the CLI from npm with Yarn:
Download the stitch-cli
binary¶
You can download the stitch-cli
binary directly from the Stitch UI.
- Navigate to the Deploy page from the left-hand navigation.
- Select the Import/Export tab.
- 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.

Add the stitch-cli
binary to your system PATH¶
- Linux / macOS
- Windows
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
.
You can check which directories are listed in your PATH
by running the following from the command line:
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:
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:
- Depending on which version of Windows you’re running, right click My Computer or This PC and select Properties.
- Click Advanced Properties, then Environment Variables.
In the Environment Variables window, your PATH
variable is listed under System Variables.
(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:
To confirm that stitch-cli
has execution permissions, navigate to
the directory containing the binary and run the following command:
The output of this command should resemble the following:
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.
General Options¶
The following options are available for all stitch-cli
commands:
-
--config-path
<File System Path>
¶ - Optional.
If included with
stitch-cli login
, stores information about the authenticated session in a file at the specified path. Session information includes your MongoDB Cloud username, API Key, and a session refresh token.If included with any other command, authenticates the request with the session saved at the specified path (if it exists) instead of the current CLI authentication state.
-
--disable-color
¶
- Optional.
If specified, 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.
-
--yes
¶
- Optional.
If specified, automatically respond affirmatively to any yes/no prompts from
stitch-cli
.
Authentication¶
Authenticate a CLI User¶
-
stitch-cli login
¶
Use stitch-cli login
to authenticate a MongoDB Cloud user with a
MongoDB Atlas programmatic API Key.
-
--api-key
<api key>
¶ A valid public MongoDB Atlas programmatic API key for the MongoDB Cloud account you wish to log in with.
-
--private-api-key
<private api key>
¶ A valid private MongoDB Atlas programmatic API key for the MongoDB Cloud account you wish to log in with.
-
--username
<MongoDB Cloud username>
¶ (Deprecated) The username of the MongoDB Cloud account you wish to log in with using personal API keys.
Log Out the Current CLI User¶
-
stitch-cli logout
¶
Use stitch-cli logout
to log out the currently logged in user.
View the Currently Logged In User¶
-
stitch-cli whoami
¶
Use stitch-cli whoami
to see details on the user that is currently
logged in to the CLI, if applicable.
If there is a currently logged-in user, their information will display on the next line in the following format:
If no user is logged in, stitch-cli
will return the following
message:
Stitch Applications¶
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.
-
--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 ofapp_id
defined in stitch.json. Ifstitch.json
does not have anapp_id
value,stitch-cli
prompts you to create a new application.New Application App IDs
If you create a new application with
stitch-cli
, Stitch generates a new App ID and ignores any value that you specify for the--app-id
flag.
-
--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 astitch.json
file in the current application directory.
-
--strategy
['merge|replace|replace-by-name']
¶ - Optional.Default: Merge
The import strategy that
stitch-cli
should use when reconciling imported entities.
-
--project-id
<MongoDB Cloud 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.
-
--include-hosting
¶
- Optional.
If specified, uploads and deploys any static assets in the
/hosting/files
directory of your Stitch application.
-
--include-dependencies
¶
- Optional.
If specified, uploads and deploys any external dependencies included in a
node_modules
archive in the/functions
directory of your Stitch application.
Export an Application¶
-
stitch-cli export
¶
Use stitch-cli export
to save a Stitch application configuration to
a local application directory.
-
--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 specified,
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.
-
--include-hosting
¶
- Optional.
If specified, exports all hosted static assets in the
hosting/files
directory of your Stitch application.
-
--for-source-control
¶
- Optional.
If enabled,
stitch-cli
exports the application configuration without any fields that conflict with deployment via GitHub source control, including fields likename
,app_id
,location
, anddeployment_model
in thestitch.json
file as well as theconfig.clusterName
field in theconfig.json
of any Atlas clusters linked to the application.
-
--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.
Diff Pending Application Changes¶
-
stitch-cli diff
¶
Use stitch-cli diff
to return a diff of the configuration files
between the deployed application and your local application directory.
The diff resembles the following:
-
--include-hosting
¶
- Optional.
If specified, the diff includes a list of files in the
hosting/files
directory of your Stitch application that are different from your app’s deployed files.
Secrets¶
List All Secrets¶
-
stitch-cli secrets list
¶
Use stitch-cli secrets list
to return a list that contains the Name
and ID of each Secret in your application.
The returned list of secrets resembles the following:
Create a Secret¶
-
stitch-cli secrets add
¶
Use stitch-cli secrets add
to create a new Secret with the specified name and value.
-
--name
<Secret Name>
¶ A unique name for the new Secret. If an existing Secret already has the specified name then this operation will fail.
-
--value
<Secret Value>
¶ The value of the new Secret.
Update a Secret’s Value¶
-
stitch-cli secrets update
¶
Use stitch-cli secrets update
to change the value of an existing
Secret in your application.
-
--secret-name
<Secret Name>
¶
-
--name
<Secret Name>
¶ The name of the Secret to update.
-
--secret-id
<Secret ID>
¶
-
--id
<Secret ID>
¶ The ID value of the Secret to update.
-
--value
<Secret Value>
¶ The new value of the Secret.
Remove a Secret¶
-
stitch-cli secrets remove
¶
Use stitch-cli secrets remove
to delete an existing Secret from your application.
-
--secret-name
<Secret Name>
¶
-
--name
<Secret Name>
¶ The name of the Secret to remove from your application.
-
--secret-id
<Secret ID>
¶
-
--id
<Secret ID>
¶ The ID value of the Secret to remove from your application.
Import Strategies¶
When performing an application import, there are multiple built-in strategies for handling existing entities.
All imports default to the merge
strategy unless otherwise
specified.
Merge¶
Under the merge
strategy, entities in the application directory are
added to the application non-destructively. Any existing entities in an
application are left unchanged if they are not represented in the
imported application directory.
If an imported entity’s id
value matches the id
of an existing
entity, the existing entity will be updated to match the imported
entity. Stitch assigns system-generated id
values to
entities without id
values before importing them as new entities.
If an entity is imported with an id
that does not match an
existing entity, the import will fail. Importing an entity with a
non-ObjectID id
value causes an error.
Note
If an imported entity has an id
field, the value must be an
ObjectID or the merge will fail.
Example
An existing application has three functions:
merge
strategy.After importing, the application has the following functions:
FunctionA
was updated based on its imported configuration file.
FunctionB
and FunctionC
were not included in the imported
application directory, so they remained unchanged after importing
with the merge
strategy. FunctionD
was imported as a new
entity and assigned a system-generated id
value.
Replace¶
Under the replace
strategy, if an imported entity’s id
value
matches the id
of an existing entity, Stitch replaces the
existing entity with the imported entity. If an imported entity’s id
value does not match an existing entity, the import fails.
If an existing entity’s id
does not match
the id
of any imported entity, Stitch deletes that
existing entity.
Stitch generates id
values for entities that lack id
values before importing them as new entities. Importing an entity with
a non-ObjectID id
value does not throw an error.
Example
An existing application has three functions:
replace
strategy.After importing, the application has the following functions:
FunctionA
was updated based on its imported configuration file.
FunctionB
and FunctionC
were not included in the imported
application directory, so they are not present in the app after
importing with the replace
strategy. FunctionD
and
FunctionE
were imported as new entities and assigned
system-generated id
values.
Replace by Name¶
Under the replace-by-name
strategy, if an imported entity’s name
value matches the name
of an existing entity, Stitch
replaces the existing entity with the imported entity. If an imported
entity’s name
value does not match an existing entity, the entity
becomes a new entity. If an existing entity’s name
does not match
the name
of any imported entity, Stitch deletes that
existing entity.
If an imported entity has no name
value, stitch-cli
will throw
an error.
Example
An existing application has three functions:
replace
strategy.After importing, the application has the following functions:
Both the existing application and the imported configuration directory
contained functions with the names FunctionB
and FunctionC
.
As a result, both functions retained their previous id
values and
names. The rest of both function’s values reflect the values uploaded
from the configuration files. FunctionA
was not included in the
imported application directory, so it is not present in the app after
importing with the replace-by-name
strategy. FunctionZ
was
imported as a new entity and assigned a system-generated id
value.