What is the difference between embedding and referencing documents?

MongoDB and Mongoose · Freshers and experienced

Model answer

Embedding stores related data inside one document (an order with its line items), which is fast to read together. Referencing stores an id pointing to another document (an order with a userId), which avoids duplication and unbounded growth. Embed data that is read together and bounded in size. Reference data that is shared or grows without limit.

Learn this topic

Connect Express to MongoDB with Mongoose in the course MERN Stack Full Course: MongoDB, Express, React and Node.js.

Sign in to add your own answer.

More questions