Is there any way to enforce camelCased field and collection names?

We have internal conventions to always camelCase field and collection names, but developers are prone to forgetfulness and honest mistakes. As per Murphy’s Law, anything that can go wrong will go wrong.

Without an enforcement mechanism, snake_case, PascalCase, UPPER_CASE, Space Case, and other strange cases are bound to appear, and once they get coded throughout the system, they become difficult and time consuming to fix. Each individual occurrence doesn’t have a hugely negative impact by itself, but when they add up over time, overall they become a significant barrier to readability and increase mental burden (worst of all it just ain’t pretty to look at!).

In the same spirit, we love using ESLint and Prettier in our javascript-based projects because they provide instant feedback, reduce the amount of decisions we have to make, and save us from ever having to think about, watch for, or argue about style violations.

The post Mongo Schema Diagram or Report has info about ways to get the schema details for the collections. I think you can extract the field names by each collection from the output of a method and check if the field names meet the conventions - by using another script.

1 Like