title: Mongoexport auth error using mechanism "SCRAM-SHA-1"
body: <p>I have taken over undocumented Mongo 4.4.8 cluster (PSA). I am trying to tidy it up and test thouroughly.</p>
  <p>An original connection string:</p>
  <pre><code>MONGODB_URI=mongodb://${USER}:${PASS}@10.0.0.3:27017,10.0.0.6:27017,10.0.0.2:27017/bud?replicaSet=bud-replica&amp;authSource=admin
  </code></pre>
  <p>I have enabled localhost and socket connection. I can log in from cmdline with</p>
  <pre><code>mongo -u ${USER} -p ${PASS}
  MongoDB shell version v4.4.8
  connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&amp;gssapiServiceName=mongodb
  Implicit session: session { &quot;id&quot; : UUID(&quot;492e331b-417e-458a-83c7-9db6eaae0869&quot;) }
  MongoDB server version: 4.4.8
  </code></pre>
  <p>I can switch db to <em>bud</em> and perform the queries. But if I run just</p>
  <pre><code>mongo
  </code></pre>
  <p>then the authentication with the same credentials does not work:</p>
  <pre><code>bud-replica:PRIMARY&gt; db.auth('admin','admin');
  Error: Authentication failed.
  0
  </code></pre>
  <p>I tried to search for users but shows there arent any:</p>
  <pre><code>bud-replica:PRIMARY&gt; db.getUsers()
  [ ]
  bud-replica:PRIMARY&gt; use bud
  switched to db bud
  bud-replica:PRIMARY&gt; db.getUsers()
  [ ]
  </code></pre>
  <p>This is <code>mongod.conf</code> security part:</p>
  <pre><code>security:
     authorization: enabled
     keyFile: &quot;/etc/bud-rs&quot;
  </code></pre>
  <p>Finally I need to export my data before doing experiments. Though the cmd line interface looks similar, mongoexport cannot fetch the data, regardless I set user/password or skip these arguments.</p>
  <pre><code>mongoexport -h localhost --db=bud -u ${USER} -p ${PASS} -c=accidents --jsonArray &gt; accidents.json
  2021-08-25T19:30:30.631+0200    could not connect to server: connection() error occured during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism &quot;SCRAM-SHA-1&quot;: (AuthenticationFailed) Authentication failed.
  mongoexport -h localhost --db=bud -u ${USER} -p ${PASS} -c=accidents --jsonArray --authenticationDatabase “admin” &gt; accidents.json
  2021-08-25T19:36:18.738+0200    could not connect to server: connection() error occured during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism &quot;SCRAM-SHA-1&quot;: (AuthenticationFailed) Authentication failed.
  root@10:~# mongoexport -h localhost --db=bud -u ${USER} -p ${PASS} -c=accidents --jsonArray --authenticationDatabase “bud” &gt; accidents.json
  2021-08-25T19:38:21.174+0200    could not connect to server: connection() error occured during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism &quot;SCRAM-SHA-1&quot;: (AuthenticationFailed) Authentication failed.
  </code></pre>
  <p>I am really confused and I failed to find a solution on Google or SO.</p>
  <p>Second relevant question:</p>
  <p>If I need to create new user, shall I do it on all replicas or it is automatically synchronized?</p>
  <p><strong>1st update</strong></p>
  <p>This is the workaround, but my questions are still valid. I want to understand.</p>
  <pre><code>root@10:~# mongoexport --db=bud -u ${USER} -p ${PASS} -c=accidents --jsonArray &quot;mongodb://admin:admin@10.0.0.3:27017/bud?authSource=admin&quot; &gt; accidents.json
  2021-08-25T20:46:54.777+0200    connected to: mongodb://[**REDACTED**]@10.0.0.3:27017/bud?authSource=admin
  2021-08-25T20:46:55.778+0200    [........................]  bud.accidents  0/4379  (0.0%)
  2021-08-25T20:46:56.497+0200    [########################]  bud.accidents  4379/4379  (100.0%)
  2021-08-25T20:46:56.497+0200    exported 4379 records
  </code></pre>
  <p><strong>2nd update</strong></p>
  <pre><code>bud-replica:PRIMARY&gt; use admin
  bud-replica:PRIMARY&gt; show collections
  system.keys
  system.users
  system.version
  bud-replica:PRIMARY&gt; db.system.users.find()
  { &quot;_id&quot; : &quot;admin.admin&quot;, &quot;userId&quot; : UUID(&quot;769e4f5c-6f46-4153-857e-47d7d8730066&quot;), &quot;user&quot; : &quot;admin&quot;, &quot;db&quot; : &quot;admin&quot;, &quot;credentials&quot; : { &quot;SCRAM-SHA-1&quot; : { &quot;iterationCount&quot; : 10000, &quot;salt&quot; : &quot;32/AP4019eome36j8n
  </code></pre>