Schema Design Assistance

44 views
Skip to first unread message

Owen Thomas

unread,
Aug 22, 2018, 9:41:54 PM8/22/18
to mongodb-user
I am very new to Mongo and NoSQL in general having come from 20 years of RDBMS experience.

If someone can point me to a good book or detailed website it would be a great place to start. A lot of what I've seen so far takes you down one maybe 2 levels whereas I have worked on system where sql statements contain multiple table joins and joins to views with multiple table joins in the views.

So looking for some guidance / help on how best to design my schema objects. So this is a very rough design I might create for a new system to manage users within an organisation to help them track their progress. It has errors I know but looking for concepts not syntactic correctness.

  • A user has one or more profiles
  • A user has one or more contact details
  • A user builds up a number of achievements
  • An achievement will utilise a number of skill and provide a number of benefits

So with my limited knowledge the document would look something like this

{
    "firstname": "peter",
    "lastname": "piper",
    "UserProfile":{
        "OrgId": "654456",
        "TeamName": "Nerds and innovators",
        "CostCenter": "CC987987"
    },
    "UserContacts":{
        "Email": "the....@email.com",
        "Mobile": "0321654987",
        "DDI": "+61.236235234x123",
        "Address": "Somewhere in a Country"
    },
    "achievements":[
        {
            "UserAchievement": "Achievement_1",
            "benefits": ["Benefit1", "Benefit2"],
            "skills": ["skill1", "skill2"]
        },
        {
            "UserAchievement": "Achievement_2",
            "benefits": ["Benefit1", "Benefit2"],
            "skills": ["skill1", "skill2"]
        }
    ]
}

Does this look sensible?

Also if I have predefined lists of reference data I want to maintain such as a list of possible skills or contact types do I maintain these as seperate collections within my db.

I've got lot's more questions such as how do I read and write elements from the skills array for a specific achievement.

Thanks in advance

A

unread,
Aug 23, 2018, 11:49:01 AM8/23/18
to mongodb-user
Looks good to me, just would say naming convention, try to be consistent with upper\lower cases.   Also, having "User" in UserProfile and UserContacts may be redundant, just have "Profile" and "Contacts" 

Wan Bachtiar

unread,
Sep 18, 2018, 1:10:50 AM9/18/18
to mongodb-user

So looking for some guidance / help on how best to design my schema objects. So this is a very rough design I might create for a new system to manage users within an organisation to help them track their progress.

Hi Owen,

It’s been a while since you posted this question, have you found a suitable schema for your application ?

Generally, the suitability of the schema design is tied closely to how the application interacts with the data. See also Data Modeling Introduction.

A number of comments based on your example:

  • Based on the diagram, UserContacts should be an array
  • Based on the diagram, UserProfile should be an array
  • The value of skills would be within array of an array, find out how the application would query this, and whether it meets the criteria. i.e. performance.
  • Consider a scenario on how a user would update their skills. i.e. remove a skill and add a skill.
  • Consider a scenario where multiple applications would update benefits at the same time.

The above are just few example comments to consider based on what you’ve provided. Analyse how the application interacts with the data more to discover benefits/weakness of different schemas.

See also Blog: 6 Rules of Thumb for MongoDB Schema Design

Regards,
Wan.

Reply all
Reply to author
Forward
0 new messages