What is a reasonable way to structure relationships in MongoDB

I am also using Node – which I am not the most familiar with – if the articles/books/tutorials pertained to this also – that would help even more.

I come from a mostly MySQL background – but in this api, all data is going to be served as JSON – so at first glance, using Mongo made a lot of sense (I could be wrong). One thign I have been unable to wrap my head around though, is relational models. e.b. Object has many Assets.

To use some examples most people would be familiar with, let’s assume I am trying to do something like:

  • Select a blog post and all of its comments. or
  • Select a photo gallery and all of its photos

Is it as simple as storing a call back inside of my assets like this?:

Photo {
    __id: 5,
    content: '...',
    gallery_id: 9 
}

And performing a .find({ gallery_id: 9 })?

I know this would work, but is that best practice? I am very new to Document Databases, and have not seen much on this particular topic.

4

Coincidentally, I am in the process of thinking through a new application using Node and MongoDB.

I have lightly used MongoDB in the past and found the MongoDB documentation data modeling to be a great starting point. The approach that you describe, storing a reference in the parent and using a second find to get the referenced items, is a perfectly good way to go about it, if you choose to make use of references rather than directly embedding the children in the parent object.

However, there might be some better ways to go at this. I have been looking into using Mongoose as an Object Document Mapper (ODM). It is the officially supported ODM for Node per the MongoDB documentation.

It provides a number of useful features, particularly if you are building a fairly complex model within the application, including pseudo-joins using the populate function. The population capability provides a more structured approach to managing references allowing for retrieval of parent and children in one step.

0

MongoDB models relationships by using references.

To normalize data, store references between two documents to indicate
a relationship between the data represented in each document.

In general, use normalized data models:

  • when embedding would result in duplication of data but would not provide sufficient read performance advantages to outweigh the
    implications of the duplication.
  • to represent more complex many-to-many relationships.
  • to model large hierarchical data sets.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

What is a reasonable way to structure relationships in MongoDB

I am also using Node – which I am not the most familiar with – if the articles/books/tutorials pertained to this also – that would help even more.

I come from a mostly MySQL background – but in this api, all data is going to be served as JSON – so at first glance, using Mongo made a lot of sense (I could be wrong). One thign I have been unable to wrap my head around though, is relational models. e.b. Object has many Assets.

To use some examples most people would be familiar with, let’s assume I am trying to do something like:

  • Select a blog post and all of its comments. or
  • Select a photo gallery and all of its photos

Is it as simple as storing a call back inside of my assets like this?:

Photo {
    __id: 5,
    content: '...',
    gallery_id: 9 
}

And performing a .find({ gallery_id: 9 })?

I know this would work, but is that best practice? I am very new to Document Databases, and have not seen much on this particular topic.

4

Coincidentally, I am in the process of thinking through a new application using Node and MongoDB.

I have lightly used MongoDB in the past and found the MongoDB documentation data modeling to be a great starting point. The approach that you describe, storing a reference in the parent and using a second find to get the referenced items, is a perfectly good way to go about it, if you choose to make use of references rather than directly embedding the children in the parent object.

However, there might be some better ways to go at this. I have been looking into using Mongoose as an Object Document Mapper (ODM). It is the officially supported ODM for Node per the MongoDB documentation.

It provides a number of useful features, particularly if you are building a fairly complex model within the application, including pseudo-joins using the populate function. The population capability provides a more structured approach to managing references allowing for retrieval of parent and children in one step.

0

MongoDB models relationships by using references.

To normalize data, store references between two documents to indicate
a relationship between the data represented in each document.

In general, use normalized data models:

  • when embedding would result in duplication of data but would not provide sufficient read performance advantages to outweigh the
    implications of the duplication.
  • to represent more complex many-to-many relationships.
  • to model large hierarchical data sets.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật