mongo shell连接mongodb

  |   0 评论   |   107 浏览

参考:链接

1. Start the mongo Shell and Connect to MongoDB

mongo "mongodb://alice:Admin!2#@mongodb0.examples.com:28015/?authSource=admin"

mongo --username alice --password --authenticationDatabase admin --host mongodb0.examples.com --port 28015

2. Connect to a MongoDB Replica Set

mongo "mongodb://mongodb0.example.com.local:27017,mongodb1.example.com.local:27017,mongodb2.example.com.local:27017/?replicaSet=replA"
mongo --host replA/mongodb0.example.com.local:27017,mongodb1.example.com.local:27017,mongodb2.example.com.local:27017

If using the DNS Seedlist Connection Format, you can specify the connection string:

mongo "mongodb+srv://server.example.com/"

Use of the +srv connection string modifier automatically sets the ssl option to true for the connection.

3. TLS/SSL Connection

mongo "mongodb://mongodb0.example.com.local:27017,mongodb1.example.com.local:27017,mongodb2.example.com.local:27017/?replicaSet=replA&ssl=true"

mongo --ssl --host replA/mongodb0.example.com.local:27017,mongodb1.example.com.local:27017,mongodb2.example.com.local:27017

Working with the mongo Shell

db
use <database>
use myNewDatabase
db.myCollection.insertOne( { x: 1 } );
db.getCollection("3 test").find()
db.getCollection("3-test").find()
db.getCollection("stats").find()

Format Printed Results

db.myCollection.find().pretty()

.mongorc.js File

When starting, mongo checks the user’s HOME directory for a JavaScript file named .mongorc.js


标题:mongo shell连接mongodb
作者:SmiteLi
地址:https://smite.site/articles/2019/11/29/1575015937344.html

评论

发表评论