The following list contains some facts and problems that I stumbled across in my MongoDB journey. It was a good lesson on what problems you can face in a production environment when you or your company decide to jump onto the latest Hype Train of technology. Fool me once, shame on you; fool me twice, shame on me.

I will update this post from time to time to mark the fixed problems - the current speed is 1 fixed ticket per year. It has been some years since I had to use this database, but I guess it could only improve from that point. Last update: 2017-09-06

Are you thinking about using MongoDB? Don’t give up yourself, there is help in form of a different database out there.

Backup/Restore

  • TOOLS-106 mongorestore has a hardcoded filename for the oplogreplay option, if you want to replay any other file you have to rename the file to oplog.bson. Fixed in 3.3.1.
  • TOOLS-111 Full restore of a MongoDB Sharded Cluster is now disabled in the MongoDB code. Trying to do so will give you the error message: Cannot do a full restore on a sharded system. You can still do it manually by following my guide How to backup and restore a MongoDB Sharded Cluster.

MongoDB Management Service (MMS)

  • The Profile Data option for each server will contain the same data that you can find in the mongod.log. I expected that the Monitoring Agent will grab data of the system.profile collection, which includes a detailed lockStats field.

Replication

  • SERVER-7680 replSetSyncFrom is a nice feature if it would work like one would have expected it to be implemented. If you add a new member to a replicaset it will always sync from the master. This feature could have been useful to take some load of the master and sync from a secondary instead. Executing this command while the initial sync from master is running will not do anything. Update: This ticket was closed because of Duplicate but I could not find the ticket that it duplicates. I guess this is just the Mongodb way of fixing substantial problems.
  • Using mongodump and mongorestore to clone an existing replicaset member for seeding a new member will not work, when you add this seeded member to the replicaset you will get a replSet initial sync drop all databases message telling you that this member will start with empty databases and do a full sync.

Service/Tools

  • SERVER-9275 The official RPM for MongoDB includes a wrong path inside the /etc/init.d/mongod startup script. Fixed in 2.5.3.
  • Some binary of the mongo package may fail to start printing out the error message what(): locale::facet::_S_create_c_locale name not valid. You can fix that by running the shell command export LC_ALL=C.

Server

  • SERVER-1240 MongoDB uses database locking. If you are writing into a collection, the whole database containing this collection is locked for reads or other writes. This is some really bad stuff that you should consider while you are designing your database layout. You could put each collection into a database that just contains this collection. Fixed in 2.7.8.
  • SERVER-863 To reduce the object size it is recommend to shorten the field names. At the moment, the translation from shorter to longer readable names needs to be implemented at application layer.
  • Dropping a collection will not free disk space nor work when you run out of disk space: exception: Dropping collection failed on the following hosts: 127.0.0.1:27017: { assertion: “Can’t take a write lock while out of disk space”

Sharding

  • If you lose all data of your config server in a sharded environment and try to add those filled server as shard you will get: “errmsg” : “can’t add shard server1:27017 because a local database ’test’ exists in another shard0000:server2:27017”
  • In case that you lose the config.chunks collection and try to restart your sharded cluster, all collections will have a disabled sharded state and will only know about the data that resists on the primary shard of every database. When you try to re-enable sharding for a collection and the balancer starts to run, MongoDB will not recognize the data that still resists on the secondary shards but instead delete all of them and grinning at you with the warning [migrateThread] warning: moveChunkCmd deleted data already in chunk
  • There is no option to exclude databases or collections from balancing.

Shell

  • Using find() in mongo shell will limit the shown results automatically, if you add an .explain() to this command this automatically limitation will not be used and the whole table will be scanned. This could block your database if you run this on a large collection (and worse: on a production deployment). If possible, always add and limit() before explain(), even a high number as limit will help in such a case. In case you want to kill such an op, use db.currentOp() to find the op that blocks the database and run db.killOp() with opid as parameter.
  • SERVER-9779 The text search scoring can’t be influenced by other fields.

TTL Indexes