Using the example in the previous subsection, instead of creating a separate table for phone numbers, in MongoDB, simply include the phone numbers as an embedded array. Here is an example from the users collection. Note how we store multiple email addresses and phone numbers as embedded arrays within the otherContact field:
db.users.findOne({},{"userKey":1,"otherContact":1,"_id":0});
{
"userKey" : "CHARROSS3456",
"otherContact" : {
"emails" : [
"[email protected]",
"[email protected]"
],
"phoneNumbers" : [
"100-688-6884",
"100-431-1074"
]
}
Thus, when a user document is deleted, all of the related information is deleted at the same time, completely avoiding the issue of orphaned information.