Options when invoking the shell

Here are some common command line options (https://docs.mongodb.com/manual/reference/program/mongo/#options) when invoking mongo:

  • mongo: Opens up the interactive command shell.
  • mongo -u username -p password -h host --port nnnn --ssl: The first two options are needed when security has been configured. The next two options are needed when accessing a remote MongoDB instance. The last option secures the command stream using TLS or SSL. Also, refer to the Chapter 7Securing MongoDB, in this book for more information on setting up TLS/SSL.
  • mongo some_JavaScript_file.js: Executes a JavaScript file containing MongoDB commands.
  • mongo --eval 'JavaScript': Directly runs the JavaScript commands in quotes.
  • mongo --help ...

Get MongoDB 4 Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.