MongoDB¶
Connect to MongoDB¶
kubectl -n mongodb exec -it mongodb-0 -c mongodb -- mongosh "mongodb://root:<PASSWORD>@localhost:27017/fmio?authSource=admin"
Port forward to MongoDB¶
kubectl -n mongodb port-forward pod/mongodb-0 27767:27017 --address 0.0.0.0 > /dev/null 2>&1 &
kubectl -n mongodb port-forward pod/mongodb-1 27768:27017 --address 0.0.0.0 > /dev/null 2>&1 &
kubectl -n mongodb port-forward pod/mongodb-2 27769:27017 --address 0.0.0.0 > /dev/null 2>&1 &
DbGate connections string (separate)¶
mongodb://root:<PASSWORD>@localhost:27767/fmio?authSource=admin&directConnection=true
mongodb://root:<PASSWORD>@localhost:27768/fmio?authSource=admin&directConnection=true
mongodb://root:<PASSWORD>@localhost:27769/fmio?authSource=admin&directConnection=true
Copy collection¶
kubectl -n mongodb exec -it mongodb-0 -c mongodb -- bash -lc '
set -euo pipefail
URI="mongodb://root:<PASSWORD>@localhost:27017/fmio?authSource=admin"
SRC="clubs-fresh-20260205" # Change this to the source collection
DST="clubs-enrichment-test-20260205" # Change this to the destination collection
rm -rf /tmp/mongodump-copy
mkdir -p /tmp/mongodump-copy
mongodump --uri="$URI" --collection="$SRC" --out=/tmp/mongodump-copy
mongorestore --uri="$URI" \
--nsInclude="fmio.$SRC" \
--nsFrom="fmio.$SRC" \
--nsTo="fmio.$DST" \
--drop \
/tmp/mongodump-copy/fmio
echo "Done: fmio.$SRC -> fmio.$DST"
'
2026-02-05T12:50:48.373+0000 writing fmio.clubs-fresh-20260205 to /tmp/mongodump-copy/fmio/clubs-fresh-20260205.bson
2026-02-05T12:50:49.578+0000 done dumping fmio.clubs-fresh-20260205 (7572 documents)
2026-02-05T12:50:49.713+0000 The --db and --collection flags are deprecated for this use-case; please use --nsInclude instead, i.e. with --nsInclude=${DATABASE}.${COLLECTION}
2026-02-05T12:50:49.714+0000 building a list of collections to restore from /tmp/mongodump-copy/fmio dir
2026-02-05T12:50:49.714+0000 don't know what to do with file "/tmp/mongodump-copy/fmio/prelude.json", skipping...
2026-02-05T12:50:49.714+0000 reading metadata for fmio.clubs-fantasy-20260205 from /tmp/mongodump-copy/fmio/clubs-fresh-20260205.metadata.json
2026-02-05T12:50:49.763+0000 restoring fmio.clubs-fantasy-20260205 from /tmp/mongodump-copy/fmio/clubs-fresh-20260205.bson
2026-02-05T12:50:52.712+0000 [######..................] fmio.clubs-fantasy-20260205 32.3MB/124MB (25.9%)
2026-02-05T12:50:55.712+0000 [############............] fmio.clubs-fantasy-20260205 65.9MB/124MB (52.9%)
2026-02-05T12:50:58.713+0000 [###################.....] fmio.clubs-fantasy-20260205 98.9MB/124MB (79.5%)
2026-02-05T12:51:01.107+0000 [########################] fmio.clubs-fantasy-20260205 124MB/124MB (100.0%)
2026-02-05T12:51:01.107+0000 finished restoring fmio.clubs-fantasy-20260205 (7572 documents, 0 failures)
2026-02-05T12:51:01.108+0000 restoring indexes for collection fmio.clubs-fantasy-20260205 from metadata
2026-02-05T12:51:01.108+0000 index: &idx.IndexDocument{Options:primitive.M{"name":"club_ls_id_1", "unique":true, "v":2}, Key:primitive.D{primitive.E{Key:"club_ls_id", Value:1}}, PartialFilterExpression:primitive.D(nil)}
2026-02-05T12:51:01.108+0000 index: &idx.IndexDocument{Options:primitive.M{"name":"fmio_id_1", "unique":true, "v":2}, Key:primitive.D{primitive.E{Key:"fmio_id", Value:1}}, PartialFilterExpression:primitive.D(nil)}
2026-02-05T12:51:03.894+0000 7572 document(s) restored successfully. 0 document(s) failed to restore.
Done: fmio.clubs-fresh-20260205 -> fmio.clubs-fantasy-20260205
Verify¶
URI="mongodb://root:<PASSWORD>@localhost:27017/fmio?authSource=admin"
SRC="clubs-fresh-20260205" # Change this to the source collection
DST="clubs-fantasy-20260205" # Change this to the destination collection
kubectl -n mongodb exec -it mongodb-0 -c mongodb -- bash -lc "
mongosh \"$URI\" --eval '
const SRC = \"$SRC\";
const DST = \"$DST\";
print(\"src docs:\", db.getCollection(SRC).countDocuments());
print(\"dst docs:\", db.getCollection(DST).countDocuments());
print(\"src idx:\", db.getCollection(SRC).getIndexes().length);
print(\"dst idx:\", db.getCollection(DST).getIndexes().length);
'
"
src docs: 7572
dst docs: 7572
src idx: 3
dst idx: 3