title: mongodb authentication disable and enable issue
body: <p>Now I have a mongoDB in my computer,locates at c:\mongodb\bin. At first, it is auth disable. so when I press:</p>
  
  <blockquote>
    <p>C:\Windows\system32>mongo</p>
  </blockquote>
  
  <p>There is some warnings:</p>
  
  <blockquote>
    <p>2018-03-28T16:53:43.516+0800 I CONTROL  [initandlisten] ** WARNING:
    Access contr ol is not enabled for the database.
    2018-03-28T16:53:43.516+0800 I CONTROL  [initandlisten] **<br>
    Read and wri te access to data and configuration is unrestricted.</p>
  </blockquote>
  
  <p>So I tried to add access control to mongoDB. What I did are:</p>
  
  <blockquote>
  <pre><code>C:\mongodb\bin&gt;use admin
  db.createUser(
    {
      user: "myUserAdmin",
      pwd: "abc123",
      roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
    }
  )
  </code></pre>
  </blockquote>
  
  <p>But after I did above, still I can log in MongoDb without username and pwd. Even after I restart the mongoDB service, or restart the computer. eg:</p>
  
  <blockquote>
  <pre><code>C:\Windows\system32&gt;mongo
  MongoDB shell version v3.4.9
  connecting to: mongodb://127.0.0.1:27017
  MongoDB server version: 3.4.9
  Server has startup warnings:
  2018-03-28T16:53:43.515+0800 I CONTROL  [initandlisten]
  2018-03-28T16:53:43.516+0800 I CONTROL  [initandlisten] ** WARNING: Access contr
  ol is not enabled for the database.
  2018-03-28T16:53:43.516+0800 I CONTROL  [initandlisten] **          Read and wri
  te access to data and configuration is unrestricted.
  2018-03-28T16:53:43.516+0800 I CONTROL  [initandlisten]
  2018-03-28T16:53:43.516+0800 I CONTROL  [initandlisten] Hotfix KB2731284 or late
  r update is not installed, will zero-out data files.
  2018-03-28T16:53:43.516+0800 I CONTROL  [initandlisten]
  &gt; show dbs
  admin  0.000GB
  local  0.000GB
  &gt; use admin
  switched to db admin
  &gt;
  </code></pre>
  </blockquote>
  
  <p>The only way that I can make the mongodb change to authentication is delete the mongodb service and install this service again by using follwoing script:</p>
  
  <blockquote>
  <pre><code>C:\mongodb\bin&gt;sc delete MongoDB  
  C:\mongodb\bin&gt;mongod --dbpath C:\mongodb\data --logpath C:\mongodb\log\MongoDB.log --auth --install
  </code></pre>
  </blockquote>
  
  <p>But If I use this way to create the auth mongoDB, when I try to login without username and pwd, it will faied as below:</p>
  
  <blockquote>
  <pre><code>C:\Windows\system32&gt;mongo
  MongoDB shell version v3.4.9
  connecting to: mongodb://127.0.0.1:27017
  MongoDB server version: 3.4.9
  &gt; show dns
  2018-03-28T17:59:06.344+0800 E QUERY    [thread1] Error: don't know how to show
  [dns] :
  shellHelper.show@src/mongo/shell/utils.js:906:11
  shellHelper@src/mongo/shell/utils.js:659:15
  @(shellhelp2):1:1
  &gt; show dbs
  2018-03-28T17:59:10.073+0800 E QUERY    [thread1] Error: listDatabases failed:{
          "ok" : 0,
          "errmsg" : "not authorized on admin to execute command { listDatabases:
  1.0 }",
          "code" : 13,
          "codeName" : "Unauthorized"
  } :
  _getErrorWithCode@src/mongo/shell/utils.js:25:13
  Mongo.prototype.getDBs@src/mongo/shell/mongo.js:62:1
  shellHelper.show@src/mongo/shell/utils.js:769:19
  shellHelper@src/mongo/shell/utils.js:659:15
  @(shellhelp2):1:1
  &gt;
  </code></pre>
  </blockquote>
  
  <p>So I can NOT create a user and pwd for this mongoDB. How could I login?</p>
  
  <p>Anybody can tell me how to do the setting step by step to make my mongoDB to authentication? or delete a old mongoDB and create a new one with authutication and also with username and pwd?</p>
  
  <p>I will get an exception below if I tried to set a without auth mongoDB and auth one.</p>
  
  <blockquote>
  <pre><code>C:\Windows\system32&gt;mongod --auth --port 27017 --dbpath C:\mongodb\data
  2018-03-28T16:49:43.874+0800 I CONTROL  [initandlisten] MongoDB starting : pid=7
  988 port=27017 dbpath=C:\mongodb\data 64-bit host=wolf-PC
  .....
  2018-03-28T16:49:43.877+0800 I STORAGE  [initandlisten] exception in initAndList
  en: 98 Unable to create/open lock file: C:\mongodb\data\mongod.lock Another program is using this file.... Is a mongod instance already running?, terminating
  </code></pre>
  </blockquote>
  
  <p>I checked the questions:
  <a href="https://stackoverflow.com/questions/41615574/mongodb-server-has-startup-warnings-access-control-is-not-enabled-for-the-dat">MongoDB: Server has startup warnings &#39;&#39;Access control is not enabled for the database&#39;&#39;</a></p>
  
  <p>which I failed to follow with step4 on above excpetion.</p>
  
  <p><a href="https://stackoverflow.com/questions/36660117/mongodb-server-has-startup-warnings">MongoDB: Server has startup warnings</a></p>
  
  <p>I got the same exception.</p>
  
  <p>So anyone can give me a detail soultion?</p>