0

I am in the midst of developing an app relying on MongoDB as its database.

In my specific case, I am doing a one to many (approximately 200) schema design. A good example for what I am doing would be if I had two Collections: Class and Students. (I do need both collections as I will be searching the Students from many different Classes). But, when I go to look at a Class, it should bring up all of its Students and list them out by name, gpa, home address, etc...

So now my question: Is this an issue that points towards denormalization or $lookup. Is it better to store the Student _id, name, gpa, etc all denormalized in the Class collection? Or am I better off simply storing the Student _id's and then using $lookup to get the corresponding information from each of the Students?

Thanks in advance!

Edit

I disagree that this is a duplicate of the linked question. Nowhere in the answers or the question is the topic of $lookup discussed.

user3858610
  • 175
  • 1
  • 14
  • $lookup is just a lookup by _id reference within an aggregation. The important concepts of when to embed vs. reference drive the decision regardless of being able to use $lookup in an aggregate pipeline. Anyways, you've already got two collections, you wouldn't want to duplicate all that student in all the classes and deal with keeping all the copies up to date. – JohnnyHK Sep 10 '16 at 14:34
  • @JohnnyHK thank you that makes a lot of sense! – user3858610 Sep 10 '16 at 14:38

0 Answers0