title: MongoDB: server returned error on SASL authentication step: Authentication failed
body: <p>I'm trying to monitor MongoDB using <code>docker</code>, <code>prometheus</code> and <a href="https://github.com/dcu/mongodb_exporter" rel="nofollow noreferrer">mongodb_exporter</a>. I have also seen <a href="https://stackoverflow.com/questions/32785910/sasl-authentication-failed-on-mongodb-database">this question</a> on stackoverflow but it doesn't help me in current situation.</p>
  
  <p>I have used the following docker-compose file to make the mongodb service up.</p>
  
  <pre><code>version: '3'
  services: 
    mongo:
      image: mongo
      container_name: mongo
      restart: always
      environment: 
        MONGO_INITDB_ROOT_USERNAME: root
        MONGO_INITDB_ROOT_PASSWORD: example
    prometheus:
      image: prom/prometheus
      restart: always
      ports:
        - 9090:9090
  </code></pre>
  
  <p>The above configuration successfully run. I have downloaded the mongodb_exporter using the following command:</p>
  
  <pre class="lang-sh prettyprint-override"><code>wget https://github.com/dcu/mongodb_exporter/releases/download/v1.0.0/mongodb_exporter-linux-amd64
  </code></pre>
  
  <p>and then run the command which is written below:</p>
  
  <pre class="lang-sh prettyprint-override"><code>./mongodb_exporter-linux-amd64 -logtostderr -mongodb.uri 'mongodb://root:example@localhost:27017' -groups.enabled 'assert, durability, background_flushing, connections, extra_info, global_lock, index_counters, network, op_counters, op_counters_repl, memory, locks, metrics'
  
  </code></pre>
  
  <p>but I face with this error:</p>
  
  <blockquote>
    <p>Listening on :9001 (scheme=HTTP, secured=no, clientValidation=no)
    E0810 13:49:59.679747    8412 connection.go:48] Cannot connect to server using url mongodb://root:example@localhost:27017: server returned error on SASL authentication step: Authentication failed.</p>
  </blockquote>
  
  <p>Becuase of the error, I can't see all of the metrics on <code>localhost:9001</code>. What should I do to solve this problem?</p>