Things got a little backed up - we're processing the data and things should be back to normal within the hour.

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Can an array of sub-documents/embedded documents be unbounded?
Post Body

I saw this question during a course on Mongo University which to create a one to many relationship between a customer document and a transaction document. The reason why option B is wrong is because transactions as a separate array can become unbounded. What I can't understand is why option C is supposed to be correct? Can't the the array of sub-documents used to represent the transaction also grow unbounded?

Consider a banking database that stores information on customers, such as their contact information, account information, and all account activity information. A one-to-many relationship exists between the customer and their transactions.

Which of the following are valid ways to represent this one-to-many relationship between the customer and their transactions? (Select all that apply.)

Incorrect Answer

a. Create two collections: one collection for the customers' identifying information and one collection for the transactions. In the transactions collection, each document contains a customer's transactions and a field to reference the customer's information document. >Your Answer: Correct

Explanation: This is a common way to model a one-to-many relationship with document references. Embedding the customer's information document inside each transaction document would lead to repetition of the customer's information. To avoid repetition of customer information, use references and keep the customer information in a separate collection from the transactions collection.

b. Create a collection that contains documents for each customer. The document contains embedded sub-documents for the contact information and account information, as well as an array that holds all their transactions. Your Answer: Incorrect

You don't want to create an unbounded array in your schema. The array that holds all transactions could become an unbounded array.

**c. Embed the transactions for each customer as an array of sub-documents in the corresponding customer document.
Your Answer: Correct**

This is a common way to model a one-to-many relationship with embedded documents. Embedding connected data in a single document can reduce the number of read operations that are required to obtain data. You should structure your schema so that your application receives all of its required information in a single operation. If your application frequently retrieves the transactions data with the customer's information, you should consider embedding so that your application doesn't need to issue multiple queries to resolve the references. Remember that the maximum size of a document is 16 MB.

Author
Account Strength
100%
Account Age
7 years
Verified Email
Yes
Verified Flair
No
Total Karma
52,363
Link Karma
17,058
Comment Karma
35,152
Profile updated: 2 days ago
Posts updated: 6 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
9 months ago