- MongoDB 4 Quick Start Guide
- Doug Bierer
- 261字
- 2021-08-13 15:25:05
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 7, Securing 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 help on using the mongo command shell.
- exit: Invokes quit(), which closes the shell returning you to the command line.
The mongo command line options shown here can be combined. As an example, to run a script abc.js on a remote MongoDB server remote.mongo.com, as user fred and with a password of flintstone, the command might appear as follows:
mongo abc.js -h remote.mongo.com -u fred -p flintstone
mongo abc.js -h remote.mongo.com -u fred -p flintstone
Before you invoke the shell, it is extremely important to make sure the MongoDB database is up and running! If, after running the mongo command you see a message similar to this, the database instance is probably not running:
$ mongo
MongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017
2018-07-04T10:41:29.866+0700 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:251:13
@(connect):1:6
exception: connect failed
$ mongo
MongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017
2018-07-04T10:41:29.866+0700 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:251:13
@(connect):1:6
exception: connect failed
推薦閱讀
- Mastering Mesos
- Microsoft Power BI Quick Start Guide
- 大數據戰爭:人工智能時代不能不說的事
- 構建高質量的C#代碼
- 大數據安全與隱私保護
- Associations and Correlations
- Implementing Oracle API Platform Cloud Service
- 電氣控制與PLC技術應用
- 突破,Objective-C開發速學手冊
- Mastering Game Development with Unreal Engine 4(Second Edition)
- Mastering Text Mining with R
- Containerization with Ansible 2
- Ubuntu 9 Linux應用基礎
- 智能機器人技術:安保、巡邏、處置類警用機器人研究實踐
- 新手學Illustrator CS6平面廣告設計