Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

mongodump on Payload Cloud db

default discord avatar
tinoutilast year
2

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.



@364124941832159242

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
    last year

    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
    tinoutilast year

    Thanks for the script

    @364124941832159242

    !



    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 on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.