Final Exam question 4

I don’t see a one → many relationship from “restaurants” → “users” is included in the correct answer. The question specifically states how to represent the one → many relationship. Please explain.

Hey @Stefan_Constantinides,

Welcome to the MongoDB Community Forums! :smile:

The solution is using Extended Reference. One restaurant will have multiple users(ie. many people can visit one restaurant), hence one many relationship.
The question statement is,

represent the One-to-Many relationship between restaurants and each 
user's last-visited restaurant to enable easy removal of a user's activity in 
accordance with GDPR

hence, we are building a users collection with an extended reference to a restaurants document, so that it is easy to delete a user with all the information about it. If the user information was also located in the restaurant document(ie. the other way around), we would have to also search for this information and delete it.

The Extended Reference to the restaurant also allows our application to know the restaurant name without having to do an additional query when we look at a user.

You can read more here: Extended Reference

Let us know if there’s any doubt about this. Also, if you feel there can be a better solution than the one given in the options, please feel free to suggest that as well. Please feel free to reach out for anything else as well.


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.