1.進(jìn)入mongodb命令行管理
C:\Documents and Settings\Administrator>mongo
MongoDB shell version: 1.8.1
connecting to: test
2.顯示數(shù)據(jù)庫
> show dbs
admin (empty)
local (empty)
test_db 0.03125GB
3.使用數(shù)據(jù)庫
> use test_db
switched to db test_db
4.添加數(shù)據(jù)庫用戶
> db.users.save({username:"gerald"})
5.查找數(shù)據(jù)庫用戶
> db.users.find()
{ "_id" : ObjectId("4ddf396e641b4986d346fe89"), "username" : "gerald" }
6.添加隸屬于某個數(shù)據(jù)庫的用戶
> use test_db
switched to db test_db
> db.addUser("gerald","123456")
{
"user" : "gerald",
"readOnly" : false,
"pwd" : "f528f606b8635241c7f060408973b5b9"
}
7.以用戶驗證的身份登錄數(shù)據(jù)庫
> use test_db
switched to db test_db
> db.auth("gerald","123456")
1
PS: 1代表驗證成功, 0代表驗證失敗