Mongodb database Schema Design with shared data

前端 未结 3 1547
别跟我提以往
别跟我提以往 2021-01-15 05:06

Hi I am newbie to mongodb.I am using java.

I have 4 tables Tenant,system,authorization in my relational table.

Something like this.

Table          


        
3条回答
  •  滥情空心
    2021-01-15 05:29

    You are still thinking in relational databases. MongoDB, however, is a document-oriented database.

    1. artificial ID numbers are usually not needed, because every document automatically has a _id field, which is a GUID (as good as guaranteed to be globally unique).
    2. relation tables should not be used in MongoDB. n-type relations are made with arrays fields instead. So when 1 system has N authorizations it uses, your system document should have a field "authorization" which is an array of the object IDs of the authorizations it has. Yes, that would be a horrible violation of the normalization rules of relational databases. But you don't have a relational database here. In MongoDB it is practical to represent N-relations with arrays, because arrays are transparent to the query language.

提交回复
热议问题