LinuxCommandLibrary

mongosh

modern MongoDB shell

TLDR

Connect to local database

$ mongosh
copy
Connect to specific database
$ mongosh [mongodb://host:27017/dbname]
copy
Connect with authentication
$ mongosh -u [user] -p [password] [dbname]
copy
Execute script file
$ mongosh [dbname] [script.js]
copy
Evaluate expression
$ mongosh --eval "[db.collection.find()]"
copy
Use specific shell
$ mongosh --nodb
copy
Quiet mode
$ mongosh --quiet [script.js]
copy

SYNOPSIS

mongosh [options] [connectionstring] [filenames]

DESCRIPTION

mongosh is the modern MongoDB shell. It provides JavaScript interface with enhanced features.
The tool replaces legacy mongo shell. Includes syntax highlighting, autocomplete, and snippets.

PARAMETERS

CONNECTIONSTRING_

MongoDB connection URI.
-u USER
Username for authentication.
-p PASSWORD
Password for authentication.
--eval EXPR
Evaluate JavaScript expression.
--nodb
Start without database connection.
--quiet
Silence non-essential output.
--help
Display help information.

CAVEATS

Requires Node.js runtime. MongoDB 5.0+ recommended. Different API from legacy mongo.

HISTORY

mongosh was released by MongoDB in 2020 as the next-generation shell replacement for the legacy mongo shell.

SEE ALSO

mongo(1), mongod(1), mongoimport(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community