Mongodb for DBAs: Week2

CRUD & administrative commands

Posted by Borg on January 25, 2017

CRUD

CRUD因在另一门课Mongodb for Developers: Week2笔记中基本覆盖,所以重复内容不再做笔记。也可参考官方文档

Bulk() operations and methods

var bulk = db.items.initializeUnorderedBulkOp();
bulk.insert({item:1})
bulk.insert({item:2})
bulk.insert({item:3})
bulk.execute()  # 这步时上面的insert才作为一次请求发送给数据库

bulk可以进行除了insert外的操作,如update/delete,同样需要execute才会写入数据库,但不能execute多次。

Commands

文档
db.runCommand({ command }) 调用命令

db.runCommand({isMaster:1})
db.runCommand("isMaster")
db.isMaster()
db.serverStatus()
db.currentOp()
db.killOp(opid)
db.collection.stats()
db.collection.drop()
  • server level: isMaster, serverStatus, logout, getLastError
  • db level: dropDatabase, repairDatabase, clone, copydb, dbStats
  • collection level:
    • DBA: create, drop, collStats, renameCollection
    • User: count, aggregate, mapreduce, findAndModify, geo*
  • index level: ensureIndex, dropIndex