Heya! Mongo newbie here, I'd love some pointers as to how to use the
mongodump
command with my Mongo Connection String provided by Payload Cloud in order to make a backup of my project.
@jmikrut would you have any pointers? I've tried things like
mongodump --db mongodb+srv://thelongmongoconnnectionstringthatsinthepayloadcloudadmin
but getting a
'.' is an invalid character in the database name
error.
i think it's because you're passing a full connection string to the
--db
flag, when really, you should be passing the url and db name separately
#!/usr/bin/env bash
# Migrates mongo from source to dest
set -eou pipefail
# Set the following variables:
SOURCE_HOST=mongodb://localhost
SOURCE_DB=my-source-db
DEST_HOST=mongodb://localhost
DEST_DB=my-dest-db
GREEN='\033[0;32m'
NC='\033[0m'
echo -e "${GREEN}> Dumping $SOURCE_DB from $SOURCE_HOST${NC}"
mongodump --uri=$SOURCE_HOST -d $SOURCE_DB
echo -e "${GREEN}> Restoring to $DEST_DB${NC}"
mongo --eval "db.dropDatabase()" $DEST_DB
mongorestore --uri=$DEST_HOST -d $DEST_DB dump/$SOURCE_DB
echo -e "${GREEN}> Complete.${NC}"
this is a script that we use to migrate a db from one place to another, so if you just look at the first half of the script, you should see how we would format this
Thanks for the script @jmikrut !
To answer my initial question for future folks looking at this, this is the command:
mongodump --uri=$SOURCE_HOST -d $SOURCE_DB
Where
$SOURCE_HOST
is the part in yellow in your Payload Cloud mongo connection string and
$SOURCE_DB
is the part in blue.
Cheers! 🙌
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.