官术网_书友最值得收藏!

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 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
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
主站蜘蛛池模板: 利津县| 岑巩县| 金川县| 揭东县| 孟连| 繁峙县| 靖西县| 定南县| 乐至县| 桐柏县| 霍林郭勒市| 罗江县| 黑水县| 昭苏县| 安宁市| 益阳市| 翼城县| 百色市| 图们市| 璧山县| 尼勒克县| 台江县| 孙吴县| 四子王旗| 宿松县| 吉木乃县| 福州市| 咸阳市| 云梦县| 木兰县| 乌鲁木齐县| 鞍山市| 昌图县| 缙云县| 宿松县| 舟曲县| 阿拉善盟| 利川市| 宝应县| 黑山县| 公安县|