Skip to content

mongosh

manage mongodb using the command line

mongosh

mongosh is the tool to work with mongodb on the CLI

mongosh

list databases

show databases

show collections

first open the database, then show the collections

use databaseName
show collections

database backup

backup all databases:

kubectl exec -it --tty mongodb-foo-bar -- sh -c '/usr/bin/mongodump --compressors=zstd --archive' | zstd - -o mongodb_$(date +%F).zst

backup just mydb:

kubectl exec -it --tty mongodb-foo-bar -- sh -c '/usr/bin/mongodump --compressors=zstd --db mydb --archive' | zstd - -o mydb_mongodb_$(date +%F).zst