酥油饼txt微盘:MongoDB学习——数据库管理命令

来源:百度文库 编辑:九乡新闻网 时间:2024/04/29 03:03:59
MongoDB学习——数据库管理命令2011年05月27日 星期五 15:38

1.进入mongodb命令行管理
C:\Documents and Settings\Administrator>mongo
MongoDB shell version: 1.8.1
connecting to: test

 

2.显示数据库
> show dbs
admin   (empty)
local   (empty)
test_db 0.03125GB

 

3.使用数据库
> use test_db
switched to db test_db

 

4.添加数据库用户
> db.users.save({username:"gerald"})

 

5.查找数据库用户
> db.users.find()
{ "_id" : ObjectId("4ddf396e641b4986d346fe89"), "username" : "gerald" }

 

6.添加隶属于某个数据库的用户
> use test_db
switched to db test_db
> db.addUser("gerald","123456")
{
        "user" : "gerald",
        "readOnly" : false,
        "pwd" : "f528f606b8635241c7f060408973b5b9"
}

 

7.以用户验证的身份登录数据库
> use test_db
switched to db test_db
> db.auth("gerald","123456")
1

PS: 1代表验证成功, 0代表验证失败