工具
从 这里 下载。
Mongo Shell
1 2 3 4 5 6 7 8 9
| # 下载 $ wget https://downloads.mongodb.com/compass/mongosh-1.1.9-linux-x64.tgz
# 解压 $ tar -xf mongosh-1.1.9-linux-x64.tgz $ cd mongosh-1.1.9-linux-x64
# 查看帮助 $ ./bin/mongosh -h
|
参数
1 2 3 4 5 6 7 8 9
| # 格式 $ mongosh [options] [db address] [file names (ending in .js or .mongodb)]
# options -u username -p password
# example $ mongosh mongodb://192.168.0.5:9999
|
读取 secondary 节点
参考 这里 和 这里。
Read Operations on a Secondary Node
When using the legacy mongo shell to connect directly to secondary replica set member, you must run mongo.setReadPref()
to enable secondary reads.
When using mongosh
to connect directly to a secondary replica set member, you can read from that member if you specify a read preference of either:
1
| mongodb://mongos1.example.com,mongos2.example.com/?readPreference=secondary&readPreferenceTags=dc:ny,rack:r1&readPreferenceTags=dc:ny&readPreferenceTags=
|
1 2
| # 连接时添加 readPreference 参数 $ mongosh mongodb://192.168.0.5:9999/?readPreference=secondary
|