Single or Multiple Entities Per Collection in DocumentDB

后端 未结 3 1539
無奈伤痛
無奈伤痛 2020-12-02 18:56

Should there be one entity per collection in document DB?

Consider I have foreign key relationship in below diagram:

3条回答
  •  抹茶落季
    2020-12-02 19:36

    Your question is a bit subjective, as you're asking for entity design, and for that, there's no single right answer.

    However: From a more objective standpoint: There's nothing stopping you from having multiple entity types within a collection (e.g. Company document type and Employee document type, in your case).

    You'd need to include some type of hint for yourself (maybe a type property) to help differentiate between the two when running your queries. But, by having both types within the same collection, you now have a collection-scope to work within. Regarding a type property: Since DocumentDB indexes all properties by default, a type property would be easy to integrate into your queries.

    EDIT Removed part about 3-collections-per-capacity-unit, as that arrangement was removed when DocumentDB shifted from Preview to Production.

提交回复
热议问题