title: MongoDB C# Driver failed to run database command authenticate
body: <p>I want to authenticate to MongoDB with C# not through passing the Connection String/Credentials on the <code>MongoClient()</code> instance. It's like we do it on MongoDB Shell, We call <code>monog -&gt; db.auth(&lt;username&gt;,&lt;password&gt;)</code> it means Connect to database first and authenticate after that.</p>
  
  <ol>
  <li><p>Write C# Code<br>
  This is my code:</p>
  
  <pre><code>var mongoClient = new MongoClient();
  var testDB = mongoClient.GetDatabase("test");
  
  string username = txtUserName.Text;
  string password = txtPassword.Password;
  
  // Check password
  var cmd = new BsonDocument("authenticate", new BsonDocument
  {
      {"username",username },
      {"password",password }
  });
  
  var queryResult = testDB.RunCommand&lt;BsonDocument&gt;(cmd);
  </code></pre>
  
  <p>My Code connect to MongoDB and call the <em>authenticate</em> Database Command (<a href="https://docs.mongodb.org/manual/reference/command/authenticate/#dbcmd.authenticate" rel="nofollow noreferrer">described  Here. It's not the <code>db.auth()</code> Shell method</a>)to login with it</p></li>
  <li><p>Run MongoDB with <code>--auth</code> option.</p></li>
  <li>Run my Code.</li>
  </ol>
  
  <p>After step 3, I encountered this problem. My code say</p>
  
  <blockquote>
    <p>Additional information: Command authenticate failed: field missing/wrong type in received authenticate command.</p>
  </blockquote>
  
  <p>I have read MongoDB documents (Also the link I added above) I can't find What I was missing.</p>