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
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 ✌️
And here is the AWS troubleshooting instruction:
https://docs.aws.amazon.com/documentdb/latest/developerguide/troubleshooting.connecting.htmlStar
Discord
online
Get help straight from the Payload team with an Enterprise License.