mongo
the Mongo command-line tool
TLDR
Connect to a local database on the default port (mongodb://localhost:27017)
$ mongo
Connect to a database
$ mongo --host [host] --port [port] [db_name]
Authenticate using the specified username on the specified database (you will be prompted for a password)
$ mongo --host [host] --port [port] --username [username] --authenticationDatabase [authdb_name] [db_name]
Evaluate a JavaScript expression on a database
$ mongo --eval '[JSON.stringify(db.foo.findOne())]' [db_name]
Name
mongo - the Mongo command-line tool
Synopsis
mongo [OPTIONS] [DB_ADDRESS] [FILE+]
Description
mongo is a JavaScript shell (with GNU readline capabilities). It supports interactive and non-interactive use. When used interactively, JavaScript can be used to query the database or perform any other function normally available with SpiderMonkey. Database output is displayed in JSON format.
If JavaScript files are specified on the command line, the shell will run non-interactively, running each one in sequence and then exiting.
Examples
- mongo
- start the shell, connecting to the server at localhost:27017 and using the test database
- mongo foo
- start the shell using the foo database at localhost:27017
- mongo 192.169.0.5/foo
- start the shell using the foo database at 192.169.0.5:27017
- mongo 192.169.0.5:9999/foo
- start the shell using the foo database at 192.169.0.5:9999
- mongo script1.js script2.js script3.js
- run three scripts and exit
Options
- --shell
- run the shell after executing files
- --help
- show usage information
- --host HOST
- server to connect to (default HOST=localhost)
- --port PORT
- port to connect to (default PORT=27017)
- --nodb
- do not connect to mongod
- --eval SCRIPT
- evaluate JavaScript
- --shell
- run the shell after executing files
- --quiet
- be less chatty
- --version
- show version information
- --verbose
- increase verbosity
- --ipv6
- enable IPv6 support (disabled by default)
- -u|--username USERNAME
- specify user to log in as
- -p|--password PASSWORD
- specify password of user
Copyright
Copyright 2007-2011 10gen
See Also
For more information, please refer to the MongoDB wiki, available at http://www.mongodb.org.
Author
Kristina Chodorow