const adminUser = process.env.MONGO_INITDB_ROOT_USERNAME;
const adminPassword = process.env.MONGO_INITDB_ROOT_PASSWORD;
const appUser = process.env.MONGO_APP_USER;
const appPassword = process.env.MONGO_APP_PASSWORD;
const appDatabase = process.env.MONGO_DB_NAME || "Invario_Website";

if (!adminUser || !adminPassword || !appUser || !appPassword) {
  throw new Error("Missing MongoDB bootstrap credentials");
}

db = db.getSiblingDB(appDatabase);
db.createUser({
  user: appUser,
  pwd: appPassword,
  roles: [{ role: "readWrite", db: appDatabase }],
});
