Skip to content

Instantly share code, notes, and snippets.

@PoplarYang
Last active April 19, 2019 13:31
Show Gist options
  • Select an option

  • Save PoplarYang/26063b3b11cdb255fcccfbb6faa15d0a to your computer and use it in GitHub Desktop.

Select an option

Save PoplarYang/26063b3b11cdb255fcccfbb6faa15d0a to your computer and use it in GitHub Desktop.
cfg = rs.conf()
cfg.members[0].priority = 0.5
rs.reconfig(cfg)
# 1 删除
删除指定记录
db.collection.remove({})
删除collection
db.collection.drop()
删除整个库
先use,db.dropDatabase()
# 2 通过用户密码登录
mongo -uusername -ppasswd --authenticationDatabase db
# update
db.col.update(
{
'title':'MongoDB 教程'
},
{
$set:{
'title':'MongoDB'
}
}
)
# 正则
db.products.find( { sku: { $regex: /789$/ } } )
db.oplog.rs.find({"o2._id": /2018-12-12.png/})
rs1:PRIMARY> use admin
switched to db admin
rs1:PRIMARY> db.runCommand({logRotate:1});
{ "ok" : 1 }
db.products.remove(
{ qty: { $gt: 20 } },
{ writeConcern: { w: "majority", wtimeout: 5000 } }
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment