MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

Come ci si connette a un set di repliche da una shell MongoDB?

Per connetterti a un set di repliche Primary, usa la mongo shell --host opzione:

mongo --host replicaSetName/host1[:porthost1],host2[:porthost1],host3[:porthost3],etc

Ad esempio:

$ mongo --host rs1/john.local:27019,john.local:27018
MongoDB shell version: v3.4.9
connecting to: mongodb://john.local:27019,john.local:27018/?replicaSet=rs1
2017-10-12T14:13:03.094+0000 I NETWORK  [thread1] Starting new replica set monitor for rs1/john.local:27019,john.local:27018
2017-10-12T14:13:03.096+0000 I NETWORK  [thread1] Successfully connected to john.local:27019 (1 connections now open to john.local:27019 with a 5 second timeout)
2017-10-12T14:13:03.096+0000 I NETWORK  [thread1] Successfully connected to john.local:27018 (1 connections now open to john.local:27018 with a 5 second timeout)
rs1:PRIMARY> db
test
rs1:PRIMARY>

Nota: Dalle versioni 3.4.2 a 3.4.10 c'era un bug (SERVER-28072) che impediva di specificare il db dopo aver usato --host o --port.