Skip to content

Pass the mongosh password inline instead of a bare -p - #70

Merged
guanzhousongmicrosoft merged 1 commit into
documentdb:mainfrom
GuanzhouSong:users/guanzhousong/mongosh-password-flag
Aug 25, 2026
Merged

Pass the mongosh password inline instead of a bare -p#70
guanzhousongmicrosoft merged 1 commit into
documentdb:mainfrom
GuanzhouSong:users/guanzhousong/mongosh-password-flag

Conversation

@GuanzhouSong

Copy link
Copy Markdown
Contributor

A cold-start test that followed this page verbatim in a container failed on the connect step with an error that names neither authentication nor the real cause:

MongoServerError: Invalid key

Cause

The page shows:

mongosh localhost:10260 -u admin -p --authenticationMechanism SCRAM-SHA-256 ...

A bare -p makes mongosh prompt for the password. In a non-interactive shell there is nothing to type, so it sends an empty password. The resulting Invalid key gives no hint that it was an auth failure, let alone an empty-credential one.

This matters here because the page explicitly caters to scripted and container use — it already tells the reader to drop sudo in a container and to export DEBIAN_FRONTEND=noninteractive. Someone following it in exactly that context is the person most likely to hit this.

Fix

Show the inline form, and say why:

mongosh localhost:10260 -u admin -p '<PASSWORD>' --authenticationMechanism SCRAM-SHA-256 \
        --tls --tlsAllowInvalidCertificates --eval 'db.runCommand({ping: 1})'

Verification

Against a live install (packages from the repository, documentdb-setup run, gateway up):

Form Result
bare -p, non-TTY exit 1 — MongoServerError: Invalid key
-p '<PASSWORD>' inline exit 0 — { ok: 1 }

insertOne / find then round-tripped normally.

Related

The same trap exists in the documentdb.io article and is fixed there alongside several air-gapped install blockers found by the same test run: documentdb/documentdb.github.io (PR linked once opened).

Full disclosure: this line is my own from #69 — I promoted the credential-flag form ahead of the URI form to avoid percent-encoding, and traded a visible trap for a quieter one.

A cold-start test that followed this page verbatim in a container hit an
unhelpful failure on the connect step:

  MongoServerError: Invalid key

A bare -p makes mongosh prompt for the password. In a non-interactive
shell there is nothing to type, so it sends an empty password, and the
resulting error names neither authentication nor the empty credential.

The page already caters to scripted and container use, so show the form
that works there. Verified against a live install: bare -p in a non-TTY
exits 1 with the error above; the inline form returns { ok: 1 }.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f18515db-c52f-4197-aa50-d81359c7c763
Signed-off-by: Guanzhou Song <guanzhou.song@gmail.com>
@guanzhousongmicrosoft
guanzhousongmicrosoft merged commit 36c5256 into documentdb:main Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants