0

I am trying to authenticate myself as a different user from the Mongo shell. Even though I am told the authentication worked, the actual user won't change. I only seem to have this error for some user accounts and not all though, as shown in the image below.

MongoDB Error Pic

How can I fix this?

2
  • What are you expecting will change based on successful or unsuccessful auth? What are your specific shell and server versions as reported by version() and db.version()? Logging in as a new user does not automatically logout any previous users in the current session (use db.logout() for this). There are use cases where you may need to combine user permissions (for example, reading from one database and writing to another) where a single user in your environment does not have all required privileges. To see current auth'd users in the mongo shell: db.runCommand({connectionStatus : 1}).
    – Stennie
    Commented Apr 5, 2019 at 1:11
  • I think this part below answers my question Logging in as a new user does not automatically logout any previous users in the current session I thought if you authorized yourself as a new user, it would log you out of the previous users. I didn't realize that you can combine user permissions.
    – siddhu
    Commented Apr 5, 2019 at 21:46

1 Answer 1

0

Logging in as a new user does not automatically logout any previous users in the current session (use db.logout() for this).

There are some use cases where you may need to combine user permissions (for example, reading from one database and writing to another) where a single user in your environment does not have all required privileges. This is a somewhat legacy carryover from older versions of MongoDB (2.2 and earlier) that had more simplistic per-database authentication without custom roles and privileges.

To see current authenticated users in the current mongo shell session, use db.runCommand({connectionStatus : 1}).

3
  • So do you know the logic for how user permissions are combined? Why is it that some users get logged out when I authorize myself with a new user and some users are not logged out? So in my example, the user user was only logged out when I authorized myself as the dba user, but when I authorized myself as the testRead user, it just combined those permissions with the user permissions
    – siddhu
    Commented Apr 8, 2019 at 14:26
  • The permissions should be additive if you are logging into the same session. How are you confirming the user is logged out? Also, what are your versions of MongoDB shell & server as reported by version() and db.version()? I would confirm logged-in users via connectionStatus; your shell prompt only appears to show one user.
    – Stennie
    Commented Apr 8, 2019 at 21:11
  • I am using Mongo 3.6.1......And based on my example above, I can confirm that if I authorize myself first as user and then authorize myself as testRead, it will add those permissions and when I run connectionStatus, it shows both users. But when I authorize myself as dba, it replaces user, and connectionStatus shows only dba and testRead
    – siddhu
    Commented Apr 11, 2019 at 21:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .