title: MongoDB + Rails Error: Command find requires authentication
body: <p>I'm unable to run commands on MongoDB that has access control enabled from a Rails 6 app.</p>
  <p>Here's the error I get:</p>
  <pre><code>Mongo::Error::OperationFailure (command find requires authentication (13) (on localhost:27017, modern retry, attempt 1))
  </code></pre>
  <p>This is my <code>mongoid.yml</code></p>
  <pre><code>staging:
    clients:
      default:
        database: mydb_staging
        hosts:
          - localhost:27017
        user: 'julien'
        password: 'mypass'
        auth_source: admin
        auth_mech: :scram
        options:
  </code></pre>
  <p>I can connect and authenticate in mongo from the command line and i can connect to it and authenticate remotely through Robomongo.</p>
  <p>here are the users i've created:</p>
  <pre><code>&gt; use admin
  switched to db admin
  &gt; db.auth('julien', 'mypass')
  1
  &gt; db.getUsers()
  [
      {
          &quot;_id&quot; : &quot;admin.julien&quot;,
          &quot;userId&quot; : UUID(&quot;3444564f-7dcd-4283-8fb1-ce4f122ed9b8&quot;),
          &quot;user&quot; : &quot;julien&quot;,
          &quot;db&quot; : &quot;admin&quot;,
          &quot;roles&quot; : [
              {
                  &quot;role&quot; : &quot;userAdminAnyDatabase&quot;,
                  &quot;db&quot; : &quot;admin&quot;
              },
              {
                  &quot;role&quot; : &quot;root&quot;,
                  &quot;db&quot; : &quot;admin&quot;
              },
              {
                  &quot;role&quot; : &quot;readWriteAnyDatabase&quot;,
                  &quot;db&quot; : &quot;admin&quot;
              }
          ],
          &quot;mechanisms&quot; : [
              &quot;SCRAM-SHA-1&quot;,
              &quot;SCRAM-SHA-256&quot;
          ]
      }
  ]
  </code></pre>
  <p>I've even created a user with the same credentials in the specific db for the Rails app:</p>
  <pre><code>&gt; use mydb_staging
  switched to db mydb_staging
  &gt; db.getUsers()
  [
      {
          &quot;_id&quot; : &quot;mydb_staging.julien&quot;,
          &quot;userId&quot; : UUID(&quot;dc2d8ab6-4f01-4568-be9d-6486283aea14&quot;),
          &quot;user&quot; : &quot;julien&quot;,
          &quot;db&quot; : &quot;mydb_staging&quot;,
          &quot;roles&quot; : [
              {
                  &quot;role&quot; : &quot;readWrite&quot;,
                  &quot;db&quot; : &quot;mydb_staging&quot;
              }
          ],
          &quot;mechanisms&quot; : [
              &quot;SCRAM-SHA-1&quot;,
              &quot;SCRAM-SHA-256&quot;
          ]
      }
  ]
  </code></pre>
  <p>More details:</p>
  <pre><code>$ mongo --version
  MongoDB shell version v4.2.8
  git version: 43d25964249164d76d5e04dd6cf38f6111e21f5f
  OpenSSL version: OpenSSL 1.1.1  11 Sep 2018
  allocator: tcmalloc
  modules: none
  build environment:
      distmod: ubuntu1804
      distarch: x86_64
      target_arch: x86_64
  </code></pre>
  <p>Gems versions:</p>
  <ul>
  <li>rails (6.0.3.2)</li>
  <li>mongo (2.12.1)</li>
  <li>mongoid (7.1.2)</li>
  </ul>
  <p>Why can't I run commands through Rails and how do I fix this?</p>
  <p><strong>EDIT</strong></p>
  <p>Here's an example from the rails console:</p>
  <pre><code>$ RAILS_ENV=staging bundle exec rails console
  Loading staging environment (Rails 6.0.3.2)
  irb(main):001:0&gt; User.count
  Traceback (most recent call last):
          1: from (irb):1
  Mongo::Error::OperationFailure (command count requires authentication (13) (on localhost:27017, modern retry, attempt 1))
  </code></pre>