title: mongodb connect locally to vps database
body: <p>I am having problem connecting locally to mongodb on my vps. Vps has installed ubuntu 14. These are the steps ive taken:</p>
  
  <ol>
  <li>commented out rule in <code>/etc/mongod.conf</code>
  
  <ul>
  <li><code>#bind_ip = 127.0.0.1</code></li>
  <li>restarted mongo process <code>service mongod restart</code></li>
  </ul></li>
  <li>added rule to firewall so it accepts connection:
  
  <ul>
  <li><code>iptables -A INPUT -p tcp --dport 27017 -j ACCEPT</code></li>
  </ul></li>
  <li><p>created user in mongodb:</p>
  
  <pre><code>use admin
  db.createUser({
      user: 'myuser',
      pwd: 'mypassword',
      roles: ['userAdminAnyDatabase', 'dbAdminAnyDatabase']
  })
  </code></pre></li>
  </ol>
  
  <p>I read an article which stated that if you create user with above method it will be admin user for all databases, but in reality i can only connect to <code>admin</code> db successfully. If i try to connect to other <code>mydb</code> database it throws error <code>Authorization fails</code>.</p>
  
  <p>this connect works:</p>
  
  <pre><code>mongo.connect('mongodb://myuser:mypassword@myip:27017/admin',function(err, db) {
  </code></pre>
  
  <p>this one doesnt:</p>
  
  <pre><code>mongo.connect('mongodb://myuser:mypassword@myip:27017/mydb',function(err, db) {
  </code></pre>
  
  <p>How can i add user to mongo so it will allow to connect with <code>mydb</code>?</p>