Skip to main content

How can you achieve primary key - foreign key relationships in MongoDB?

Updated 1 min readMarkdown
Part of seriesMongoDB
How can you achieve primary key - foreign key
relationships in MongoDB?

There are two ways to achieve the One-to-Many (primary key - foreign key) relationships in MongoDB.

1. Model One-to-Many Relationships with Embedded Documents A data model can use embedded documents to describe a one-to-many relationship between connected data. Embedding connected data in a single document can reduce the number of read operations required to obtain data.

2. Model One-to-Many Relationships with Document References A data model can use references between documents to describe one-to-many relationships between connected data.

Sources:

Model One-to-Many Relationships With Embedded Documents — MongoDB Manual. www.mongodb.com/docs/manual/tutorial/model-embedded-one-to-many-relationships-between-documents.

Model One-to-Many Relationships With Document References — MongoDB Manual. www.mongodb.com/docs/manual/tutorial/model-referenced-one-to-many-relationships-between-documents.

About the author

  • Full Stack Developer with a passion for building web applications. PHP, Node.js, Laravel, MySQL, MongoDB. Love collaborating & making a difference

No comments yet. Be the first to comment.

More from this blog