2016-08-08 08:04:25 +01:00
|
|
|
# mongo
|
|
|
|
|
2023-08-01 08:21:03 +01:00
|
|
|
> The legacy MongoDB shell. See `mongosh` for the new shell.
|
|
|
|
> Note: all connection options can be replaced with one string: `mongodb://user@host:port/db_name?authSource=authdb_name`.
|
2019-06-04 10:25:14 +01:00
|
|
|
> More information: <https://docs.mongodb.com/manual/reference/program/mongo>.
|
2016-08-08 08:04:25 +01:00
|
|
|
|
2023-08-01 08:21:03 +01:00
|
|
|
- Connect to a local database on the default port (`mongodb://localhost:27017`):
|
2016-08-08 08:04:25 +01:00
|
|
|
|
2023-08-01 08:21:03 +01:00
|
|
|
`mongo`
|
2016-08-08 08:04:25 +01:00
|
|
|
|
2023-08-01 08:21:03 +01:00
|
|
|
- Connect to a database:
|
2016-08-08 08:04:25 +01:00
|
|
|
|
2023-08-01 08:21:03 +01:00
|
|
|
`mongo --host {{host}} --port {{port}} {{db_name}}`
|
2016-08-08 08:04:25 +01:00
|
|
|
|
2023-08-01 08:21:03 +01:00
|
|
|
- Authenticate using the specified username on the specified database (you will be prompted for a password):
|
2016-08-08 08:04:25 +01:00
|
|
|
|
2023-08-01 08:21:03 +01:00
|
|
|
`mongo --host {{host}} --port {{port}} --username {{username}} --authenticationDatabase {{authdb_name}} {{db_name}}`
|
2016-08-08 08:04:25 +01:00
|
|
|
|
2023-08-01 08:21:03 +01:00
|
|
|
- Evaluate a JavaScript expression on a database:
|
2016-08-08 08:04:25 +01:00
|
|
|
|
2023-08-01 08:21:03 +01:00
|
|
|
`mongo --eval '{{JSON.stringify(db.foo.findOne())}}' {{db_name}}`
|