title: Document database one to many - How to determine whether to reference or embed
body: <p>I am relatively new to using mongoose and mongodb and trying to figure out what questions I should be asking myself when determining whether to create a new Schema and reference or embed by adding an array to an existing schema when there is a one to many relationship.</p>
  <p><strong>For example:</strong></p>
  <p>I have a User model. I need to keep track of User checkins (this will be a button the user presses on the UI to checking, it will call a POST route to my node api). I am debating on whether to embed an array of checkins to the User model or create a separate checkin Schema and reference User. I decided to create a checkin Schema that has a User reference by id. The reason for this is so I can query all checkins throughout the entire system easily (this is a requirement). I figured if I went the other direction and added an array of checkins to the User model (Schema), I would never be able to retrieve a master list of all checkins without looping through all of the Users in the system and compiling one. Additionally, now that I created a new Schema (model) I don't think I will be able to access a specific user's checkins from the User model, I would need to do a find on Checkins where userId=userId.</p>
  <p>I am new to Mongo and Mongoose, so maybe there is a feature here that I might not be aware of.</p>
  <p>The question is:</p>
  <pre><code>User (Schema)
    checkins: [
      {
           ...
      },
    ],
  
  or
  
  User (Schema)
  Checkin (Schema)
       User
  </code></pre>