Fix issues when using MongoDB for replication