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

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
主站蜘蛛池模板: 深水埗区| 晴隆县| 玉山县| 疏附县| 宾阳县| 天长市| 镇安县| 安图县| 新沂市| 宜宾市| 微博| 宣城市| 远安县| 恩平市| 隆安县| 江阴市| 涿鹿县| 临漳县| 南和县| 卓尼县| 丹江口市| 肥城市| 东辽县| 乌苏市| 普安县| 泸水县| 太仆寺旗| 罗江县| 天门市| 中超| 外汇| 五家渠市| 盘锦市| 洮南市| 怀远县| 枣庄市| 通河县| 城市| 库尔勒市| 凌云县| 南投市|