Files
threshold/website/content/docs/commands/connect/mongo.mdx
T
4078838f56 feat(mongo): Add MongoDB connection support for Boundary CLI PORT (#6069)
* feat(mongo): add mongo for boundary cli

* Fix: remove changes added by mistake during testing

* feat(enos): install MongoDB client (mongosh) in e2e Docker test runtime

* Remove explicit Boundary DB/server startup from target_tcp_connect_mongo_test.go

* Add a full stop and trigger CI

* feat: add mongosh support to boundary connect mongo

* feat: add mongosh support to boundary connect mongo

* feat: add auth-source flag for MongoDB connect command

- Add -auth-source flag with default value 'admin' for root users
- Add BOUNDARY_CONNECT_MONGO_AUTH_SOURCE environment variable support
- Update documentation with new flag and correct mongosh default
- Improve MongoDB test with explicit auth-source parameter
- Fix Docker configuration formatting for better readability

This ensures MongoDB root users authenticate against the admin database
by default while allowing flexibility for custom authentication databases.

* test(e2e): Fixed false positive in Mongo connect test; use UriNetwork and container hostname

* make gen

* fix: Removed unnecessary variable containerName from the MongoDB E2E test

* feat(connect/mongo): Build URI compatible with mongosh and set default authSource

* feat(connect/mongo): use mongosh flags following PostgreSQL pattern

* remove 'connection string' from auth-source usage text

* Update internal/cmd/commands/connect/mongo.go

Co-authored-by: Bharath Gajjala <120367134+bgajjala8@users.noreply.github.com>

* remove 'connection string' from auth-source usage text

* refacotr: replace authSource flag with authenticationDatabase

---------

Co-authored-by: Enbiya <100806254+enbiyagoral@users.noreply.github.com>
Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
2025-10-09 11:13:47 -05:00

85 lines
2.5 KiB
Plaintext

---
layout: docs
page_title: connect mongo - Command
description: >-
The "connect mongo" command performs a target authorization or consumes an existing authorization token, and then launches a proxied MongoDB connection.
---
# connect mongo
Command: `boundary connect mongo`
The `connect mongo` command authorizes a session against a target and invokes a MongoDB client for the connection.
The command fills in the local address and port.
@include 'cmd-connect-env-vars.mdx'
## Examples
The following example shows how to connect to a target with the ID `ttcp_eTcMueUYv` using a MongoDB helper:
```shell-session
$ boundary connect mongo -target-id=ttcp_eTcZMueUYv \
-dbname=northwind \
-username=superuser \
-authentication-database=admin \
-format=table
```
When prompted, you must enter the password for the user, "superuser":
<CodeBlockConfig hideClipboard>
```plaintext
Enter password:
Current Mongosh Log ID: 64a1b2c3d4e5f6789012345
Connecting to: mongodb://127.0.0.1:12345/northwind?authSource=admin
Using MongoDB: 7.0.0
Using Mongosh: 2.0.0
northwind> show collections
orders
products
customers
northwind> db.products.count()
77
northwind>
```
</CodeBlockConfig>
## Usage
<CodeBlockConfig hideClipboard>
```shell-session
$ boundary connect mongo [options] [args]
```
</CodeBlockConfig>
@include 'cmd-connect-command-options.mdx'
### MongoDB options:
- `-dbname` `(string: "")` - The database name you want to pass through to the client.
You can also specify the database name using the **BOUNDARY_CONNECT_DBNAME** environment variable.
- `-style` `(string: "mongosh")` - How the CLI attempts to invoke a MongoDB client.
This value also sets a suitable default for `-exec`, if you did not specify a value.
The default and currently-understood value is `mongosh`.
You can also specify how the CLI attempts to invoke a MongoDB client using the **BOUNDARY_CONNECT_MONGO_STYLE** environment variable.
- `-username` `(string: "")` - The username you want to pass through to the client.
This value may be overridden by credentials sourced from a credential store.
You can also specify a username using the **BOUNDARY_CONNECT_USERNAME** environment variable.
- `-authentication-database` `(string: "")` - The authentication database for MongoDB.
If omitted, mongosh defaults `authSource` to the database name (`-dbname`). If no database is specified, it defaults to `admin`.
You can also specify the authentication database using the **BOUNDARY_CONNECT_MONGO_AUTHENTICATION_DATABASE** environment variable.
@include 'cmd-option-note.mdx'