I would like to know if there is a convention for database collections such as:
PageVisit
or page_visit
.
Are there any advantages/disadvantages for these notations?
Database names and Collection names are case sensitive. You can always recreate the DB/Collection with the appropriate name. The Mongo Shell is a interactive JS interpreter.
In MongoDB, the data records are stored as BSON documents. Here, BSON stands for binary representation of JSON documents, although BSON contains more data types as compared to JSON. The document is created using field-value pairs or key-value pairs and the value of the field can be of any BSON type.
The general conventions are:
Examples:
users pagevisits users.pagevisits
Field name conventions (should) follow some of the same logic although camel casing those is fairly common.
Just avoid using hyphens in your collection names.
And that's only because, if you use the cli of the two below calls, the first is invalid JavaScript:
db.foo-bar.find(); db['foo-bar'].find();
They are both functionally identical, but the second is slightly more annoying to type and doesn't tab-complete.
Apart from that, advantages/disadvantages depend on your use of the collections. Being consistent is more important than which convention you choose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With