Setup Database and Tables on creation

mongodb allows you to add setup scripts to docker-entrypoint-initdb.d to create initial databases / tables. They also support the following environment variables for setting up users / databases:

  MONGO_INITDB_ROOT_USERNAME
  MONGO_INITDB_ROOT_PASSWORD
  MONGO_INITDB_USERNAME
  MONGO_INITDB_PASSWORD
  MONGO_INITDB_DATABASE

Is it possible to specify this in the MongoDB operator?

1 Like

Hello @jml5qh ,

we do not support it for now in the Operator. It is possible to perform the same operations with you CICD pipeline or side tools.
Our focus is to provision the infrastructure and MongoDB itself, without going into the database.

If there is a hard requirement or blocker please let us know.

1 Like

I noticed there are references to MONGO_INITDB_ROOT_USERNAME, MONGO_INITDB_ROOT_PASSWORD, MONGO_INITDB_DATABASE, and docker-entrypoint-initdb.d in https://github.com/percona/percona-server-mongodb-operator/blob/main/build/ps-entry.sh#L218.

I was able to create a root user by adding MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD to my user secrets file, but I’m still looking into picking up the docker-entrypoint-initdb.d directory. Am I going about this wrong? Is this not supported?

1 Like