Is there a convention to name collection in MongoDB?

后端 未结 4 1207
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 07:36

I would like to know if there is a convention for database collections such as:

PageVisit or page_visit.

Are there any advantages/d

4条回答
  •  -上瘾入骨i
    2020-12-02 08:21

    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.

提交回复
热议问题