1

MongoDB uses multi-granularity locking [1] that allows operations to lock at the global, database or collection level, and allows for individual storage engines to implement their own concurrency control below the collection (i.e., at the document-level in WiredTiger).

Besides I've read that there are two possible Storage Engines for MongoDB: MMAPv1 (default) and WiredTiger. From MongoDB 3.0, the first one uses collection-level locking, the second one document-level locking. What does it mean that MongoDB allows operations to lock at the GLOBAL, DATABASE or COLLECTION level? It means that I can choose lock granularity? If yes how I can do it? Is this in contrast with lock-granularity of the chosen storage engine (for example document-level in WiredTiger)? And how can I change my storage engine from MMAPv1 to WiredTiger? Thanks in advance.

1 Answers1

1

Answer to

And how can I change my storage engine from MMAPv1 to WiredTiger?

This page explains it:

Start 3.0 mongod. Ensure that the 3.0 mongod is running with the default MMAPv1 engine.

Export the data using mongodump. mongodump --out <exportDataDestination> Specify additional options as appropriate, such as username and password if running with authorization enabled. See mongodump for available options.

Create data directory for WiredTiger. Create a new data directory for WiredTiger. Ensure that the user account running mongod has read and write permissions for the new directory.

mongod with WiredTiger will not start with data files created with a different storage engine.

Restart the mongod with WiredTiger. Restart the 3.0 mongod, specifying wiredTiger as the --storageEngine and the newly created data directory for WiredTiger as the --dbpath. Specify additional options as appropriate.

mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> You can also specify the options in a configuration file. To specify the storage engine, use the new storage.engine setting.

marijnz0r
  • 934
  • 10
  • 23
  • Thanks for explaining how to change storage engine. What about multi-granularity locking? I know what "multi-granularity locking" means in general but I didn't understand how can I choose it (or if it is automatically chosen) in MongoDB. – Mattia Micomonaco May 29 '15 at 12:56
  • As far as I know, you can't control locks yourself, but I don't know for sure. You can try to read the [FAQ](http://docs.mongodb.org/manual/faq/concurrency/) – marijnz0r May 29 '15 at 12:59