I am using a hosted MongoDB (v6 @ Digital Ocean), and they provided an admin user that I confirmed as valid to create databases, collections, and documents. I want to add a user that can only 'read' and 'write' in a specific database.
I have found this answer that points to the following solution:
client.testdb.command(
'createUser', 'newUser', pwd='Test123',
roles=[{'role': 'readWrite', 'db': 'testdb'}]
)
I can execute such a command using my admin db client and get an ok response: {'ok': 1.0, '$clusterTime': {'clusterTime': ..., 'signature': {...}, 'operationTime':...}. Although that is the case, if I query the database for a list of users (i.e., client.testdb.command('usersInfo')), I get an empty list.
Moreover, if I try to use such newUser to access the testdb, I get an Authentication failed error. (i.e., I tried to count_documents({}) -- which works well with my admin client.)
Putting together the documentation for the PyMongo command database call and the MongoDB createUser, the above call should indeed work. Can anyone see what I am doing wrong?