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.

Problem with DocumentDB connection

default discord avatar
showering_compliments8 months ago
1

I am trying configure

secondaryPreferred

but am facing the same issue.


I am trying to setup primary and replica instances


For someone who hasn't worked very closely with DB, can you explain what is happening above and how/if it fixes this ?

  • default discord avatar
    svn__2 years ago

    And here is the AWS troubleshooting instruction:

    https://docs.aws.amazon.com/documentdb/latest/developerguide/troubleshooting.connecting.html

    For anyone struggling with DocumentDB, I was able to configure it:



    1. get CA .pem file

    wget https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem

    and save it on the same level as

    server.ts

    file


    2. set correct MONGODB_URI

    mongodb://<user_with_access_to_database>:<password>@<documentdb_domain_from_aws_dashboard>:27017/<database>

    3. update configuration passed to payload.init in server.ts file:



    payload.init({
    ...
    mongoURL: process.env.MONGODB_URI,
    mongoOptions: {
            ssl: true,
            sslCA: path.resolve(__dirname, 'rds-combined-ca-bundle.pem'),
            useFacet: false,
            retryWrites: false
       }
    });


    I've also encountered

    MongoServerSelectionError: Server selection timed out after 30000 ms

    error but it was fixed by provided

    mongoOptions

    (it was probably fixed by changing tlsCAFile to sslCA). Hope it'll help someone ✌️



    Hi there! Maybe someone run into a problem with DocumentDB and

    readPreference=secondaryPreferred

    ?



    ERROR (payload): Error: cannot connect to MongoDB. Details: MongoDB prohibits index creation on connections that read from non-primary replicas.  Connections that set "readPreference" to "secondary" or "secondaryPreferred" may not opt-in to the following connection options: autoCreate, autoIndex
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.