Automated Database and DatabaseUser creation on Atlas

Hello ,

Is there a way to automate db and dbUser creation on Atlas? Even with Atlas admin i can’t create db and user via following as it is giving a permission error. My aim is to create a Jenkins Job that will be a part of automation of entire infrastructure:

use test

db.createUser(
{
    user: "test",
    pwd: "Password123",
    roles: [
    {
        role: "readWrite",
        db: "test"
    }]
})

2020-04-15T21:56:12.268+0100 E  QUERY    [js] uncaught exception: Error: couldn't add user: not authorized on test to execute command

So what do you suggest to automate this db and dbUser creation via Jenkins ?

Welcome to the community @Omer_Sen!

As noted in the documentation on Configuring Database Users:

Atlas rolls back any user modifications not made through the UI or API. You must use the Atlas UI or API to add, modify, or delete database users on Atlas clusters.

You need to use the Atlas API for automating the management of Atlas database users or other aspects of your clusters.

If you are using any infrastructure management tools, there may be a recipe available leveraging the Atlas API. For example, HashiCorp Terraform has an officially approved and tested MongoDB Atlas Provider plugin.

Regards,
Stennie