database design - MongoDB architecture best practices for storing child relationships? -
say need store manager/employee relationship in mongodb database , sake of example lets these 2 different collections. try show relationship structuring documents/db this:
manager collection document:
{ id: 1, name: "bill smith" }
employee collection documents:
{ id: 1, name: "abe smith", managerid: 1 }, { id: 2, name: "hank smith", managerid: 1 }
but see people storing relationship in way:
method #2
manager collection document:
{ id: 1, name: "bill smith", employees: [1, 2] }
employee collection documents:
{ id: 1, name: "abe smith" }, { id: 2, name: "hank smith" }
the drawback see second method employees
array out of synch if employee deleted it's collection not array.
i'm curious if can point out pros/cons of 2 different methods , if 1 considered best practice storing child relationships in mongodb?
the mongodb blog post 6 rules of thumb mongodb schema design has discussion of topic , weighs many of pros , cons.
also search "mongodb embedding vs linking" , you'll lot of references , opinions.
Comments
Post a Comment