lovesh
lovesh

Reputation: 5391

creating a different database for each collection in MongoDB 2.2

MongoDB 2.2 has a write lock per database as opposed to a global write lock on the server in previous versions. So would it be ok if i store each collection in a separate database to effectively have a write lock per collection.(This will make it look like MyISAM's table level locking). Is this approach faulty?

Upvotes: 7

Views: 1017

Answers (2)

Gates VP
Gates VP

Reputation: 45277

There's a key limitation to the locking and that is the local database. That database includes a the oplog collection which is used for replication.

If you're running in production, you should be running with Replica Sets. If you're running with Replica Sets, you need to be aware of the write lock effect on that database.

Breaking out your 10 collections into 10 DBs is useless if they all block waiting for the oplog.

Before taking a large step to re-write, please ensure that the oplog will not cause issues.

Also, be aware that MongoDB implements DB-level security. If you're using any security features, you are now creating more DBs to secure.

Upvotes: 6

MrKurt
MrKurt

Reputation: 5100

Yes that will work, 10gen actually offers this as an option in their talks on locking.

I probably isolate every collection, though. Most databases seem to have 2-5 high activity collections. For the sake of simplicity it's probably better to keep the low activity collections grouped in one DB and put high activity collections in their own databases.

Upvotes: 2

Related Questions