title: UserNotFound: Could not find user nodejs@sDatabase
body: <p>I know this question is similar to this questions:</p>
  
  <p><a href="https://stackoverflow.com/questions/50362555/usernotfound-could-not-find-user-adminautomation">UserNotFound: Could not find user admin@automation</a></p>
  
  <p><a href="https://stackoverflow.com/questions/44698748/pymongo-usernotfound-could-not-find-user-authenticatedadmin">PyMongo - UserNotFound: Could not find user authenticated@admin</a></p>
  
  <p>, but the answers coudln't help me and I'm very desperate now :(</p>
  
  <p><strong>My backend exception:</strong></p>
  
  <blockquote>
    <p>SCRAM-SHA-1 authentication failed for nodejs on sDatabase from client
    20.345.145.12 ; UserNotFound: Could not find user nodejs@sDatabase</p>
  </blockquote>
  
  <p>Mongo DB Version: 3.2.20</p>
  
  <p><strong>My frontend exception:</strong></p>
  
  <blockquote>
    <p>MongoError: Authentication failed.</p>
  </blockquote>
  
  <p>NodeJS version: 8.9.4</p>
  
  <p>NodeJS mongodb dependency version: ~3.0.10</p>
  
  <p><strong>My user:</strong></p>
  
  <pre><code>&gt; db.getUsers()
  [
          {
                  "_id" : "sDatabase.nodejs",
                  "user" : "nodejs",
                  "db" : "sDatabase",
                  "roles" : [
                          {
                                  "role" : "readWrite",
                                  "db" : "sDatabase"
                          }
                  ]
          }
  ]
  &gt;
  </code></pre>
  
  <p>My nodeJS code [which works with other mongoDB databases]:</p>
  
  <pre><code>var MongoClient = require('mongodb').MongoClient;
  
  var pwd = "1234", //also tried with encodeURIComponent
      username = "nodejs",
      host = "1234.567.898.765",
      database = "sDatabase";
  
  var url = "mongodb://" + username + ":" + pwd + "@" + host + ":27017/" + database; //also tried: ?authMechanism=SCRAM-SHA-1 //?authSource=sDatabase&amp;w=1
  
  MongoClient.connect(url, function(err, db) {
      if (err) throw err;
      console.log("Database created!");
      db.close();
  });
  </code></pre>
  
  <p>Thanks a lot for every answer and comment and helpful letter.</p>