mongo shell 连接 mongodb

本贴最后更新于 1610 天前,其中的信息可能已经渤澥桑田

参考:链接

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

  • MongoDB

    MongoDB(来自于英文单词“Humongous”,中文含义为“庞大”)是一个基于分布式文件存储的数据库,由 C++ 语言编写。旨在为应用提供可扩展的高性能数据存储解决方案。MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。它支持的数据结构非常松散,是类似 JSON 的 BSON 格式,因此可以存储比较复杂的数据类型。

    90 引用 • 59 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...