Extract DDL for users & roles

Hi Team ,
There is a requirement of generating DDL statements for users and roles that are already existing in the environment .
Required your help if there are any kind of customise scripts that I can run from mongo Shell to get the DDL of existing users and roles.


Hi :wave: @Prince_Das,

Welcome back to the MongoDB Community forums :sparkles:

Can you please clarify the above statement or provide additional details about your specific requirements?

However, if I understand your question correctly, you are looking for a way to obtain a list of all the database users with their roles. You can achieve this by using the db.getUsers() command in the MongoDB Shell. This command retrieves the necessary details you need. Make sure you have the appropriate privileges, specifically the viewUser action, to access the information of other users in their respective databases. You can find more details about this command and its usage in the MongoDB documentation on db.getUsers().

I hope this information helps! If you have any further questions or need further assistance, please feel free to reach out.

Best regards,