mongodb-linux-i686-3.0.0/bin/mongo use admin db.auth("buru","12345678") #认证,返回1表示成功 或 mongodb-linux-i686-3.0.0/bin/mongo -u buru -p 12345678 --authenticationDatabase admin
此时
show collections
报错
2015-03-17T10:15:56.011+0800 EQUERYError: listCollections failed: { "ok" : 0, "errmsg" : "not authorized on admin to execute command { listCollections: 1.0 }", "code" : 13 } at Error (<anonymous>) at DB._getCollectionInfosCommand (src/mongo/shell/db.js:643:15) at DB.getCollectionInfos (src/mongo/shell/db.js:655:20) at DB.getCollectionNames (src/mongo/shell/db.js:666:17) at shellHelper.show (src/mongo/shell/utils.js:625:12) at shellHelper (src/mongo/shell/utils.js:524:36) at (shellhelp2):1:1 at src/mongo/shell/db.js:643
2015-03-17T10:30:06.461+0800 EQUERYError: listCollections failed: { "ok" : 0, "errmsg" : "not authorized on buru to execute command { listCollections: 1.0 }", "code" : 13 } at Error (<anonymous>) at DB._getCollectionInfosCommand (src/mongo/shell/db.js:643:15) at DB.getCollectionInfos (src/mongo/shell/db.js:655:20) at DB.getCollectionNames (src/mongo/shell/db.js:666:17) at shellHelper.show (src/mongo/shell/utils.js:625:12) at shellHelper (src/mongo/shell/utils.js:524:36) at (shellhelp2):1:1 at src/mongo/shell/db.js:643 `
显然没权限,先auth:
db.auth("bao","12345678") 1 show collections news system.indexes wahaha