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.

Can we change the Mongo DB Collection Name?

default discord avatar
mrl76 months ago
5

I'm not overly sure how this has happened by our collection name for all the Payload data is set to

test

...


Can this be changed? If so where? I don't remember ever having to set the name for the table but it could have been an oversight.



Thanks all. Got it sorted

  • discord user avatar
    jacobsfletch
    last year

    The name of your db is contained within the

    MONGODB_URI

    If you need to change it, you

    should

    be able to do so manually from the Compass interface you have open, then update your

    MONGODB_URI

    string accordingly



    Otherwise you could change your

    MONGODB_URI

    first, then use the

    mongodump

    and

    mongorestore

    cli commands to migrate the old database over to the new one



    Payload will create a new database if one was not found using the connection string provided

  • default discord avatar
    yhn5790last year

    Yes, you can do it inside

    server.ts

    . [More info](

    https://payloadcms.com/docs/getting-started/installation#server

    )


    payload.init({
        secret: process.env.PAYLOAD_SECRET,
        mongoURL: process.env.MONGODB_URI,
        express: app,
        onInit: () => {
            payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
        },
        mongoOptions: {
            dbName: "payload",
        },
    });
  • discord user avatar
    denolfe
    last year

    Interesting, I've never actually seen anyone do it that way.

  • default discord avatar
    wiessonlast year

    Interesting, I was wondering why the db is always called test (I'm maintaining 5 instances of payload 😅 , and never had the time do debug that)

  • default discord avatar
    joaovbrandon7 months ago

    Seems like the

    mongoOptions

    doesn't exist in type

    InitOptions

    .


    But just to register here, like Jacob said, you can set the database in the MongoDB Connection String, that defaults to

    test

    if empty


    mongodb+srv://<username>:<password>@beyondthebasics.abcde.mongodb.net/<database>
    Ref:

    https://www.mongodb.com/resources/products/fundamentals/mongodb-connection-string
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.