18

So I have something called

exports.create = function(projectJSON){

 var project = new ProjectModel({
   id : projectJSON.id,
   projectName : projectJSON.projectName ,
   authorName : projectJSON.authorName,
   firstPostDate : projectJSON.firstPostDate

 })
}

Is the above naming convention for a multi-word element firstPostDate (camel case) correct, or should they be spaced with _ in all lowercase?

I see that other blogs prefer it to be in small caps..

EDIT:

Also I read that elements should be singular instead of plural ie:

`comment` instead of `comments` for a blog schema design
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
bouncingHippo
  • 5,940
  • 21
  • 67
  • 107

3 Answers3

29

I use Google's JSON Style Guide myself and they suggest using camelCase i.e. firstPostDate. Below is the section excerpt

Property Name Format

Property names must conform to the following guidelines:

  • Property names should be meaningful names with defined semantics.
  • Property names must be camel-cased, ascii strings.
  • The first character must be a letter, an underscore (_) or a dollar sign ($).
  • Subsequent characters can be a letter, a digit, an underscore, or a dollar sign.
  • Reserved JavaScript keywords should be avoided (A list of reserved JavaScript keywords can be found below).

These guidelines mirror the guidelines for naming JavaScript identifiers. This allows JavaScript clients to access properties using dot notation. (for example, result.thisIsAnInstanceVariable). Here's an example of an object with one property:

{
  "thisPropertyIsAnIdentifier": "identifier value"
}
Chathuranga Chandrasekara
  • 20,548
  • 30
  • 97
  • 138
Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
  • so if its just 1 huge schema with lots of other embedded documents, the first character should be `_id` instead of just `id` right? and the `id` in the embedded documents do not need to have an underscore? – bouncingHippo Nov 06 '12 at 19:57
  • @bouncingHippo Unable to understand what you are saying. All high level documents in Mongo has _id automatically created. I doesn't think you can rename it. – Aravind Yarram Nov 06 '12 at 20:03
  • lets say `"thisPropertyIsAnIdentifier"` is a string, in the schema design, shouldnt it be `"thisPropertyIsAnIdentifier" : "String"` ? – bouncingHippo Nov 06 '12 at 20:05
  • I am unable to see the difference...what do you mean by schema? Mongo has collections... – Aravind Yarram Nov 06 '12 at 20:09
6

Shortening field names is not necessary.

Check docs:

Shortening field names reduces expressiveness and does not provide considerable benefit for larger documents and where document overhead is not of significant concern. Shorter field names do not reduce the size of indexes, because indexes have a predefined structure. In general it is not necessary to use short field names.

Esteban Gatjens
  • 4,651
  • 1
  • 14
  • 8
1

Naming convention for collection.

In order to name a collection few precautions to be taken:

  1. A collection with empty string “” is not a valid collection name.

  2. A collection name should not contain the null character because this defines the end of collection name.

  3. Collection name should not start with the prefix “system.” as this is reserved for internal collections.

  4. It would be good to not contain the character $ in the collection name as various driver available for database do not support $ in collection name.

For more information, please check the link: http://www.tutespace.com/2016/03/schema-design-and-naming-conventions-in.html

Cœur
  • 37,241
  • 25
  • 195
  • 267