#commands to setup sharded db

##configsrv

```bash
kubectl exec -it $(kubectl get pods -l app=spontaneous-database-configsvr01 --namespace=development -o custom-columns=":metadata.name") -c configsvr01  --namespace development -- bash
mongosh --eval "rs.initiate({_id: '"'rs-config-server'"', configsvr: true, version: 1, members: [ { _id: 0, host :  'spontaneous-database-configsvr01:27119 ' }, { _id: 1, host :  'spontaneous-database-configsvr02:27120 ' }, { _id: 2, host :  'spontaneous-database-configsvr03:27121 ' } ] })"

```

##shard01
```bash

kubectl exec -it $(kubectl get pods -l app=spontaneous-database-shard01-node01 --namespace=development -o custom-columns=":metadata.name") -c shard01-node01  --namespace development -- bash
mongosh --eval "rs.initiate({_id: '"'rs-shard-01'"', version: 1, members: [ { _id: 0, host : '"'spontaneous-database-shard01-node01:27122'"' }, { _id: 1, host : '"'spontaneous-database-shard01-node02:27123'"' }, { _id: 2, host : '"'spontaneous-database-shard01-node03:27124'"' }, ] })"
```


##shard02
```bash

kubectl exec -it $(kubectl get pods -l app=spontaneous-database-shard02-node01 --namespace=development -o custom-columns=":metadata.name") -c shard02-node01  --namespace development -- bash
mongosh --eval "rs.initiate({_id: '"'rs-shard-02'"', version: 1, members: [ { _id: 0, host : '"'spontaneous-database-shard02-node01:27125'"' }, { _id: 1, host : '"'spontaneous-database-shard02-node02:27126'"' }, { _id: 2, host : '"'spontaneous-database-shard02-node03:27127'"' }, ] })"
```

##router01
```bash

kubectl exec -it $(kubectl get pods -l app=spontaneous-database-router01 --namespace=development -o custom-columns=":metadata.name") -c router01  --namespace development -- bash
mongosh --eval "sh.addShard('"'rs-shard-01/spontaneous-database-shard01-node01:27122'"')
sh.addShard('"'rs-shard-01/spontaneous-database-shard01-node02:27123'"')
sh.addShard('"'rs-shard-01/spontaneous-database-shard01-node03:27124'"')
sh.addShard('"'rs-shard-02/spontaneous-database-shard02-node01:27125'"')
sh.addShard('"'rs-shard-02/spontaneous-database-shard02-node02:27126'"')
sh.addShard('"'rs-shard-02/spontaneous-database-shard02-node03:27127'"')"
```

<!-- ##router02
```bash

kubectl exec -it $(kubectl get pods -l app=spontaneous-database-router02 --namespace=development -o custom-columns=":metadata.name") -c router02  --namespace development -- bash
mongosh --eval "sh.addShard('"'rs-shard-01/spontaneous-database-shard01-node01:27122'"')
sh.addShard('"'rs-shard-01/spontaneous-database-shard01-node02:27123'"')
sh.addShard('"'rs-shard-01/spontaneous-database-shard01-node03:27124'"')
sh.addShard('"'rs-shard-02/spontaneous-database-shard02-node01:27125'"')
sh.addShard('"'rs-shard-02/spontaneous-database-shard02-node02:27126'"')
sh.addShard('"'rs-shard-02/spontaneous-database-shard02-node03:27127'"')"
``` -->

## init db on router01
```bash

kubectl exec -it $(kubectl get pods -l app=spontaneous-database-router01 --namespace=development -o custom-columns=":metadata.name") -c router01  --namespace development -- bash

echo "mongosh --eval "use Spontaneous
sh.enableSharding('"'Spontaneous'"')
db.adminCommand( { shardCollection: '"'Spontaneous.History'"', key: { _id: 1 } } )
db.History.insertMany([{ '"'PlayerName'"': '"'Hans Muster'"', '"'Activity'"': '"'Skating'"', '"'ActivityCategory'"': '"'Outdoor'"' }, { '"'PlayerName'"': '"'Mirio'"', '"'Activity'"': '"'CSGO'"', 
'"'ActivityCategory'"': '"'Gaming'"' }])"
" > script.js
mogosh < script.js

```


##verify

use Spontaneous
db.History.find( {} )
sh.status()
