I have written this post to serve as some quick guidelines for how databases and collections should be named in MongoDB to keep my projects consistent. Partially derived from this StackOverflow post.
By following the guidelines from the very start of your project, these naming conventions should help you create a scalable and consistent MongoDB database.
- append DB to the end of name (e.g. myDB, myNewDB)
- Collections & document fields
- Lowercase names (collection names in MongoDB are case-sensitive)
- Plural collections (e.g. users rather than user)
- No word separators when possible – although I use CamelCase when not possible with perhaps only two separate words max; e.g. firstName, lastName.
Other general rules include:
- Keep names of databases, collections etc. as short as possible
- No special characters (unless using an _ underscore as the prefix to an internal MongoDB field e.g. _id)