Last Updated: February 25, 2016
·
2.619K
· mattcodez

DO NOT use hyphens in MongoDB collection names

I'm still new to MongoDB and recently tried to do a dump and restore to a co-worker's machine. We would get errors on his machine saying "don't know what to do with file db-name". Perplexed, I looked at my dump output. There was a file in the dump folder that was empty along with full system and session files. Googling this got me nowhere. For some reason, I decided to rename a collection to not have a hyphen in the name. Boom! All of a sudden I have two files containing data for that collection. I then rename the other collections and those start working is well. So, even though you supposedly can use hyphens in a name just by quoting the name in your queries, don't do it! Apparently the backup/restore tools don't have the same support.