---
# System prepended metadata

title: PoC Database Clustering

---

# PoC Database Clustering

* Explication de notre choix replicaset
* On a décidé d’utiliser Docker: explications containers
* Expliquer les problèmes: Blue screen sur Dell -> machine Linux externe ssh, la plupart de la doc pour Linux, tuto deprecated

## Commandes

```
docker pull mongo

docker network ls

docker network create mynetwork

docker network ls

docker run -p 30001:27017 --name mongo1 --net mynetwork mongo mongod --replSet replicaset1

docker run -p 30002:27017 --name mongo2 --net mynetwork mongo mongod --replSet replicaset1

docker run -p 30003:27017 --name mongo3 --net mynetwork mongo mongod --replSet replicaset1

docker ps

docker exec -it mongo1 mongosh
```
```
config = {
  	"_id" : "replicaset1",
  	"members" : [
  		{
  			"_id" : 0,
  			"host" : "mongo1:27017"
  		},
  		{
  			"_id" : 1,
  			"host" : "mongo2:27017"
  		},
  		{
  			"_id" : 2,
  			"host" : "mongo3:27017"
  		}
  	]
  }
```
```
rs.initiate(config)

rs.status()

db.myecamcollection.insertOne({name : 'this is your grades'})

db.myecamcollection.find()
```
```
db2 = (new Mongo('mongo2:27017')).getDB('test')

db2.getMongo().setReadPref('secondary')

db2.myecamcollection.find()

db3 = (new Mongo('mongo3:27017')).getDB('test')

db3.getMongo().setReadPref('secondary')

db3.myecamcollection.find()

rs.status()
```
ouvrir Nouveau terminal:
```
docker stop mongo2

db2.myecamcollection.find()
```