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

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
主站蜘蛛池模板: 安康市| 鄂伦春自治旗| 青州市| 盐池县| 镇雄县| 咸阳市| 荔波县| 梧州市| 年辖:市辖区| 巴里| 长治县| 云龙县| 阳朔县| 景谷| 舟山市| 会宁县| 登封市| 门头沟区| 合川市| 洛宁县| 南宁市| 红原县| 宝清县| 孝昌县| 托克托县| 广丰县| 资阳市| 贡觉县| 犍为县| 遂溪县| 临颍县| 如东县| 江阴市| 迁西县| 商洛市| 周宁县| 固镇县| 宜黄县| 宁河县| 黄浦区| 玛曲县|