What are naming conventions for MongoDB?

后端 未结 6 1082
梦如初夏
梦如初夏 2020-12-22 15:47

Is there a set of preferred naming conventions for MongoDB entitites such as databases, collections, field names?

I was thinking along these lines:

  • Dat
6条回答
  •  余生分开走
    2020-12-22 16:25

    Even if no convention is specified about this, manual references are consistently named after the referenced collection in the Mongo documentation, for one-to-one relations. The name always follows the structure _id.

    For example, in a dogs collection, a document would have manual references to external documents named like this:

    {
      name: 'fido',
      owner_id: '5358e4249611f4a65e3068ab',
      race_id: '5358ee549611f4a65e3068ac',
      colour: 'yellow'
      ...
    }
    

    This follows the Mongo convention of naming _id the identifier for every document.

提交回复
热议问题