LinuxCommandLibrary

mongo

legacy MongoDB shell

TLDR

Connect to local database

$ mongo
copy
Connect to remote database
$ mongo [mongodb://host:27017/dbname]
copy
Connect with authentication
$ mongo -u [user] -p [password] [dbname]
copy
Execute JavaScript file
$ mongo [dbname] [script.js]
copy
Evaluate expression
$ mongo --eval "[db.collection.find()]"
copy
Connect with SSL
$ mongo --ssl --host [host]
copy

SYNOPSIS

mongo [options] [dbaddress] [filenames]

DESCRIPTION

mongo is the legacy MongoDB shell. It provides interactive JavaScript interface to MongoDB.
The tool connects to mongod instances. Supports queries, administration, and scripting.

PARAMETERS

DBADDRESS_

Database connection string.
-u USER
Username for authentication.
-p PASSWORD
Password for authentication.
--eval EXPR
Evaluate JavaScript expression.
--ssl
Use SSL connection.
--host HOST
Server hostname.
--help
Display help information.

CAVEATS

Deprecated in favor of mongosh. MongoDB 4.4 and earlier. JavaScript-based.

HISTORY

mongo was the original MongoDB shell, now replaced by mongosh for MongoDB 5.0+.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community