Skip to main content

Command Palette

Search for a command to run...

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

Updated
1 min read
How can you achieve primary key - foreign key
relationships in MongoDB?
R

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

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.

More from this blog

R

Raja Muhammad Asher - Senior Software Engineer - Full Stack Developer

157 posts

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