mongodump on Payload Cloud db

default discord avatar
tinouti
3 months ago
5

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.

  • discord user avatar
    jmikrut
    Payload Team
    3 months ago

    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

  • default discord avatar
    tinouti
    3 months ago

    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! 🙌

    image.png
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.