Operation LockType Issue a query Readlock Get more datafrom a[cursor](http://docs.mongodb.org/manual/reference/glossary/#term-cursor) Readlock Insertdata Write lock Remove data Write lock Updatedata Write lock [Map-reduce](http://docs.mongodb.org/manual/reference/glossary/#term-map-reduce) Readlockand write lock, unless operationsare specified as non-atomic. Portions ofmap-reduce jobs can run concurrently. Create an index Building an indexin the foreground, which is the default, locks the databaseforextended periods of time. [db.eval()](http://docs.mongodb.org/manual/reference/method/db.eval/#db.eval "db.eval") Write lock.[db.eval()](http://docs.mongodb.org/manual/reference/method/db.eval/#db.eval "db.eval")blocks all other JavaScript processes. [eval](http://docs.mongodb.org/manual/reference/commands/#eval "eval") Write lock. If used with thenolocklock option, the[eval](http://docs.mongodb.org/manual/reference/commands/#eval "eval")option does not take a write lockand cannot write datato the database. [aggregate()](http://docs.mongodb.org/manual/reference/method/db.collection.aggregate/#db.collection.aggregate "db.collection.aggregate") Readlock
db.collection.ensureIndex(), reIndex, compact, db.repairDatabase(), db.createCollection(), when creating a very large (i.e. many gigabytes) capped collection, db.collection.validate(), db.copyDatabase().This operation may lock all databases
以下命令需要申请 exclusively 锁,但锁定很短时间。
1 2 3 4 5 6 7
db.collection.dropIndex(), db.collection.getLastError(), db.isMaster(), rs.status() (i.e. replSetGetStatus,) db.serverStatus(), db.auth(), and db.addUser().
备注:可见,一些查看命令也会锁库,在比较繁忙的生产库中,也会有影响的。
6 锁住多个库的操作
以下数据库操作会锁定多个库。
1 2 3 4 5 6
db.copyDatabase() must lock the entire mongod instance at once. Journeying, which is an internal operation, locks all databases for short intervals. All databases share a single journal. User authentication locks the admin database as well as the database the user is accessing. All writes to a replica set’s primary lock both the database receiving the writes and the local database. The lock for the local database allows the mongod to write to the primary’s oplog.