0

I am just starting a new project with MongoDb/NodeJS. As usually, I build schema field with camelCase like:

  • fullName
  • propertyType

It looks very easy for me to get data because Javascript use camelCase on code. I can directly use object return from MongoDB

But when I try to load sample data on Mongo Atlas. Every field is named as underscore:

  • full_name
  • property_type

Mongo Atlas is a leader on MongoDB server. I want to use the standard for my projects.

From my perspective, NodeJS and MongoDB is closed friends.

But I don't know why do not use camelCase instead of underscore?

  • Does this answer your question? [What are naming conventions for MongoDB?](https://stackoverflow.com/questions/5916080/what-are-naming-conventions-for-mongodb) – Positivity Jul 30 '22 at 09:44
  • Hmm, I read that before ask question. But maybe we can freely to use convention on that. Just want to know why Mongo Atlas use it? – Nguyen Manh Thang Jul 30 '22 at 10:14

1 Answers1

2

JavaScript is not the only language that MongoDB supports. Each language has its own convention.

MongoDB is written in C++. Snake_case is common with C/C++ languages as well as Python and PHP.

Snake_case is often used by JavaScript and Java when consumed by a different language eg JavaScript -> JSON -> PHP. Not long ago, PHP dominated the backend. When MongoDB was written, PHP was the king. The MongoDB driver for PHP is written in C.

Since you are writing in JavaScript, using camelCase is perfectly acceptable. If you are in a JavaScript/Node.js only environment, camelCase might be your group's standard.

However, if you are accessing a database that is already using one convention, stay with that convention.

John Hanley
  • 74,467
  • 6
  • 95
  • 159