Warmup - Mongoose Schema Practice

Warmup - Mongoose Schema Practice

Create a set of Mongoose Schemas for a Reddit-style feed to practice good structure in modeling your data. You'll need to include the following:

  • Users
  • Posts
  • Comments on the posts (these only go one level deep, no comments of comments)
  • Tags to organize posts

Consider the following: You need to decide when you will use embedded documents and when you will use ObjectId references. Check the MongoDB documentation on when each one is most useful.

Also keep in mind the helpful mnemonic "Store what you query for." The idea behind this is that you want to think carefully about the data you'll need each time you make a request of the database and organize your data structure so that you're making as few calls to the database as reasonably possible. It's helpful to ask yourself, "is this a resource I will often need to get by itself, or will it usually come closely related to some other data?" If you'll frequently need to get the data by itself, you should consider storing it separately and using ObjectId references. If you'll be mostly getting it attached to some other data, you'll likely want to just embed it in another Schema.