MongoDb基础命令

一些基础忘记随时查看. .

#整备恢复

mongodump——端口20001 authenticationDatabase=admin - u *, - c - d绿绿绿绿- o/home

mongorestore下降——,——主机172.16.201.74,端口20001——authenticationDatabase=admin -umgbackup - d测试/tmp/盖/测试/盖子。bson


#基于时间备份oplog

mongodump——端口20001,- - -地方- c oplog authenticationDatabase=admin - u * - d。rs - q的ts: {$ lt:时间戳(1462830369,1),$ gt:时间戳(1462821613,1)}}’- o/tmp/lidddd


#将oplog恢复到临时库

mongorestore - u *——authenticationDatabase=admin——主机172.16.201.73端口27017 - d - c oplog。rs,/数据/备份/oplog1/地方/oplog.rs.bson

,

#从临时库重放oplog,

mongooplog——端口20001 - u * authenticationDatabase=admin——从=172.16.201.73:27017 



oplog查找

db.oplog.rs。找到({ts: {$ lt:时间戳(1462917498,1),$ gt:时间戳(1462918425,1)}}).pretty ()



使用local 

, db.oplog.rs.find ()

日期- d @1361542596 +“Y % - % - % d % H: % m: % S”

,为(var=0; i<1000;我+ +){db.lvlv.save ({“xywy”:我})}

,

,

, sql=" db.getReplicationInfo ();"

回声“sql”美元|/usr/地方/xywy/mongodb-3.0.8/bin/mongo, 127.0.0.1:20001/admin - u * - pc ^公元8 # 1 rvx5rbg0 authenticationDatabase=admin,壳牌


添加管理用户:

,

使用管理

db.createUser (

,{

,,用户:“*”,

,,pwd:“* * * * *”,

,,角色:[{角色:“根”,db:“admin”}]

,}

)

,

添加备份用户:

使用管理

db.createUser (

,{

,,用户:“mgbackup”

,,pwd:“* * * * * * * * *”,

,,角色:[{角色:“备份”,db:“admin”},{角色:“恢复”,db:“admin”}]

,}

)

添加日常操作用户:

使用管理

db.createUser (

,{

,,用户:“mgadmin”

,,pwd:“* * * * *”,

,,角色:[{角色:“readWriteAnyDatabase”, db: admin}]

,}

)

,

,

添加读写用户:

,

使用管理

db.createUser (

, {

,,用户:“liuyunsong”

,,pwd:“* * * * *”,

,,角色:[

,,,{角色:“rw db: " 123 "}

,,)

,}

)

,

修改用户权限:

使用管理

db.runCommand (

,{

,,updateUser:“liuyaxin”,

,,pwd:“* * * *”,

,,,,,角色:[

,,{角色:“读”,db: " 123 "}

,,,,,)

,}

)

,

删除用户:

使用123

db.dropUser (“123”)

,

删除一个库下所有用户:

使用123

db。dropAllUsers ()

,

对用户添加角色:

使用123

db.runCommand ({grantRolesToUser:“*”,

,,,,,,,,,角色:[

,,,,,,,,,,{角色:“admin”, db:“admin”}

,,,,,,,,,)

,,,,,,,})

,

对用户移除角色:

使用123

db.runCommand ({revokeRolesFromUser:“liuyaxin”

,,,,,,,,,角色:[

,,,,,,,,,,{角色:“读”,db: " 234 "}

,,,,,,,,,)

,,,,,,,})

创建角色:

使用管理

db.runCommand ({createRole:“rw”

,特权:[

,,{资源:{db:“123”,收集:"},行动:[“找到”,“更新”,“插入”,“删除”]}

,),

,角色:[

,,{角色:“读”,db:“admin”}

,)

})

修改角色权限:

使用管理

db.runCommand (

,,{

,,,updateRole:“rw”,

,,,特权:

,,,,,(

,,,,,,{

,,,,,,,资源:{db:“123”,收集:"},

,,,,,,,行动:[“找到”,“更新”,“插入”,“删除”)

,,,,,,}

,,,,,,

,,,角色:

,,,,,(

,,,,,,{角色:“读”,db:“admin”}

,,,,,)

,,}

)

,

删除角色:

使用管理

db.runCommand (

,,{

,,,dropRole:“rw”,

,,,writeConcern: {w:“多数”}

,null

MongoDb基础命令