In the last recipe, we learned how to embed one object into another using record
. However, there are situations where it's better to just create a reference from one object to another. For example, let's say we are creating a system for a store and we'll need to generate some reports. It's not practical to embed order into the clients because if we did so, each time we wanted to generate a report related to orders only, we would have to fetch all clients to find the order in which we want to generate the report. So, in such situations, it makes more sense to create a reference between clients and their orders. This is what we'll learn in this recipe.
We'll evolve the project we used in the Connecting to MongoDB using record recipe. You can duplicate or modify it.