createUser with MongoDB C# driver

hi everyone, I’ve been trying for several days now to create a user using the createUser command in a mongodb atlas cluster database.
I try to summarize the theory of the error.

Through c # mongo.diriver I connect my client through a connection string in which I have the permissions of atlas admin and then I launch a “command” “” createUser "but nothing tells me that I do not have the necessary permissions.

if I try to do the same thing with mongo compass the exact same thing happens, I searched on google in the various forums but nothing I can not understand the extent of the problem I am attaching a screen where I hope you understand the matter better.

Hello @Salvatore_Lorello, welcome to the MongoDB Community forum!

It is generally recommended that you perform MongoDB Administration tasks (like, security, in your case) using the command-line interface like mongo shell. You will have interactive response to the command response at each step of what you are trying.

You can try the steps from this documentation to create MongoDB users:

of course I understand, but I have a registration form where through C # driver I should create a new user who has read and write privileges only in a specific database that is dynamically created by registering the user on the form. Peeking around a bit I had read that the only way you can create a new user is either from api or from ui. I am trying to access from api but nothing I can not just could you give me some advice?

To create a new user (e.g., “new-user-1”) with specific role (like read and write privileges on a specific database), you need to be a user (e.g., “super-1”) with user administrator privileges. This “super-1” user can create other users like “new-user-1” as required. This means you need to authenticate yourself as “super-1” - and then create the new user.

Here are some relevant documentation / links to run the Create User command from MongoDB C# Driver:

You cannot createUser with Atlas.

See:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.