ऐसा इसलिए है क्योंकि उपयोगकर्ता क्रेडेंशियल व्यवस्थापक डेटाबेस में संग्रहीत हैं और नहीं डिफ़ॉल्ट डेटाबेस में जहां मोंगो शेल (परीक्षण) से जुड़ता है।
आप इसे कनेक्शन URL से बदल सकते हैं:
admin
. के साथ डेटाबेस:
$ mongo localhost/admin --username user -p
MongoDB shell version: 2.6.9
Enter password:
connecting to: localhost/admin
replset:PRIMARY>
एक विशिष्ट डेटाबेस के बिना (test
डिफ़ॉल्ट रूप से):
$ mongo localhost --username user -p
MongoDB shell version: 2.6.9
Enter password:
connecting to: localhost
2015-04-22T15:34:28.743+0100 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1260
exception: login failed
--authenticationDatabase
. के साथ :
$ mongo localhost --username user --authenticationDatabase admin -p
MongoDB shell version: 2.6.9
Enter password:
connecting to: localhost
replset:PRIMARY>
ध्यान दें कि --host
. का उपयोग करके यह नहीं मानेंगे कि डेटाबेस का नाम /
. के बाद वाला है (स्लैश:
$ mongo --host localhost/admin --username user -p
MongoDB shell version: 2.6.9
Enter password:
connecting to: localhost/admin:27017/test
2015-04-22T15:37:40.703+0100 starting new replica set monitor for replica set localhost with seeds admin:27017
2015-04-22T15:37:40.703+0100 [ReplicaSetMonitorWatcher] starting
2015-04-22T15:37:40.920+0100 getaddrinfo("admin") failed: nodename nor servname provided, or not known
2015-04-22T15:37:40.922+0100 warning: No primary detected for set localhost
2015-04-22T15:37:40.922+0100 All nodes for set localhost are down. This has happened for 1 checks in a row. Polling will stop after 29 more failed checks
2015-04-22T15:37:40.923+0100 Error: connect failed to replica set localhost/admin:27017 at src/mongo/shell/mongo.js:148
exception: connect failed