title: Mongodb could not find user "user@database"
body: <p>I'm trying to allow a mongo user to connect to a mongo database, but regardless of what roles I give the user, the authentication fails with this error in the logs:</p>
  
  <pre><code>2019-08-09T17:03:05.486+0000 I ACCESS   [conn13] SCRAM-SHA-1 authentication failed for username on dbname from client 127.0.0.1:38790 ; UserNotFound: Could not find user username@dbname
  2019-08-09T17:03:05.488+0000 I NETWORK  [conn13] end connection 127.0.0.1:38790 (0 connections now open)
  </code></pre>
  
  <p>Here are the contents of <code>/etc/mongodb.conf</code></p>
  
  <pre><code># mongodb.conf
  
  # Where to store the data.
  dbpath=/var/lib/mongodb
  
  #where to log
  logpath=/var/log/mongodb/mongodb.log
  
  logappend=true
  
  bind_ip = 0.0.0.0
  port = 27017
  
  # Enable journaling, http://www.mongodb.org/display/DOCS/Journaling
  journal=true
  
  auth=true
  </code></pre>
  
  <p>And here is how I created the user:</p>
  
  <pre><code>db.createUser({
    user: "username",
    pwd: "secret",
    roles: [
      { role: "userAdmin", db: "dbname" },
      { role: "dbAdmin",   db: "dbname" },
      { role: "readWrite", db: "dbname" }
    ]
  });
  </code></pre>
  
  <p>I also granted the <code>dbOwner</code> role to the user on the database <code>dbname</code>. What is happening here? Why can't I connect to the database if the user is the owner and has read/write privileges? Do I have to create a user with the name <code>username@dbname</code>?</p>
  
  <p>EDIT: Just tried adding a user with the username <code>username@dbname</code>, but that user also fails to connect.</p>
  
  <p>I can also connect to mongo with the same command minus the <code>/dbname</code> at the end and then run <code>use dbname</code>. I have no clue why this would work, but connecting directly wouldn't.</p>