{"action":"created","issue":{"url":"https://api.github.com/repos/mafintosh/mongojs/issues/158","labels_url":"https://api.github.com/repos/mafintosh/mongojs/issues/158/labels{/name}","comments_url":"https://api.github.com/repos/mafintosh/mongojs/issues/158/comments","events_url":"https://api.github.com/repos/mafintosh/mongojs/issues/158/events","html_url":"https://github.com/mafintosh/mongojs/issues/158","id":48165680,"number":158,"title":"Authentication problem","user":{"login":"huzhifeng","id":3701550,"avatar_url":"https://avatars.githubusercontent.com/u/3701550?v=3","gravatar_id":"","url":"https://api.github.com/users/huzhifeng","html_url":"https://github.com/huzhifeng","followers_url":"https://api.github.com/users/huzhifeng/followers","following_url":"https://api.github.com/users/huzhifeng/following{/other_user}","gists_url":"https://api.github.com/users/huzhifeng/gists{/gist_id}","starred_url":"https://api.github.com/users/huzhifeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huzhifeng/subscriptions","organizations_url":"https://api.github.com/users/huzhifeng/orgs","repos_url":"https://api.github.com/users/huzhifeng/repos","events_url":"https://api.github.com/users/huzhifeng/events{/privacy}","received_events_url":"https://api.github.com/users/huzhifeng/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2014-11-08T13:20:58Z","updated_at":"2016-01-07T11:28:06Z","closed_at":"2014-11-08T14:04:38Z","body":"I'm trying to set password for mongodb to prevent access to any db with empty login and pass (set by default).\r\n\r\nBefore starting the mongodb with authentication, I created a user `admin` in database `admin` to enable global authentication. Then restart the mongod with `--auth`\r\n```\r\nuser admin;\r\ndb.addUser('admin', 'admin');\r\n```\r\n\r\nThere are some databases on mongodb, and my project want to connect to database `todo`, so my code is like this:\r\n```\r\ndb = mongojs('admin:admin@localhost:27017/todo');\r\n```\r\nBut I saw auth failure:\r\n```\r\nSat Nov 08 20:49:10 [conn23] auth: couldn't find user admin, todo.system.users\r\n```\r\n\r\nIt looks like verified the account in `todo.system.users` instead of `admin.system.user`\r\n\r\nI want to do global authentication before connect to specific database.\r\nHow to do this?\r\nThanks."},"comment":{"url":"https://api.github.com/repos/mafintosh/mongojs/issues/comments/169635378","html_url":"https://github.com/mafintosh/mongojs/issues/158#issuecomment-169635378","issue_url":"https://api.github.com/repos/mafintosh/mongojs/issues/158","id":169635378,"user":{"login":"dilignt","id":5586296,"avatar_url":"https://avatars.githubusercontent.com/u/5586296?v=3","gravatar_id":"","url":"https://api.github.com/users/dilignt","html_url":"https://github.com/dilignt","followers_url":"https://api.github.com/users/dilignt/followers","following_url":"https://api.github.com/users/dilignt/following{/other_user}","gists_url":"https://api.github.com/users/dilignt/gists{/gist_id}","starred_url":"https://api.github.com/users/dilignt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dilignt/subscriptions","organizations_url":"https://api.github.com/users/dilignt/orgs","repos_url":"https://api.github.com/users/dilignt/repos","events_url":"https://api.github.com/users/dilignt/events{/privacy}","received_events_url":"https://api.github.com/users/dilignt/received_events","type":"User","site_admin":false},"created_at":"2016-01-07T11:28:06Z","updated_at":"2016-01-07T11:28:06Z","body":"I'm unable to get this to work.  With the following web user I can show collections in the test database\r\n\r\n```\r\n$ mongo\r\nMongoDB shell version: 3.2.0\r\nconnecting to: test\r\n> use admin\r\nswitched to db admin\r\n> db.auth('web', 'k1ll3r5')\r\n1\r\n> use test\r\nswitched to db test\r\n> show collections\r\nstore\r\n>\r\n```\r\nBut when I try to do the equivalent using this code with mongojs with  the `authSource` option\r\n```\r\nvar mongojs = require('mongojs');\r\n\r\nvar db = mongojs('web:k1ll3r5@localhost/test?authSource=admin');\r\n\r\ndb.getCollectionNames(function(err, names) {\r\n    console.log(arguments);\r\n});\r\n```\r\nit won't authenticate\r\n```\r\n{ '0':\r\n   { [MongoError: auth failed]\r\n     name: 'MongoError',\r\n     message: 'auth failed',\r\n     ok: 0,\r\n     errmsg: 'auth failed',\r\n     code: 18 } }\r\n```\r\nWhat am I doing wrong? \r\nmany thanks"}}