Note that there are some explanatory texts on larger screens.

plurals
  1. PONode, MongoDB, Mongoose Design Choice - Creating two collections or one collection
    primarykey
    data
    text
    <p>I'm struggling with a large design choice for my applications' mongo collections and mongoose schemas.</p> <p>My applications calls for two account types: <strong>Students</strong> and <strong>Teachers</strong>.</p> <p>The only similarity between the two account types is that they both require the fields: firstName, lastName, email, and password. Other than that, they are different (teachers have "assignments", "tests", students have "homework", etc.)</p> <p>I have pondered my options extensively, and considered the following design choices:</p> <ol> <li><p>Use <strong>mongoose-schema-extend</strong>, and create an "abstract" schema for all accounts. Then, extend this schema to create the Teacher and Student schemas. This implies two collections, and therefore some redundant fields. There are also issues with logging in and account creation (checking to see if the email used to log in is a student email or teacher email, etc.)</p></li> <li><p>Create one collection "accounts", and add a <strong>type</strong> field to indicate if the account is a "student" or a "teacher". This implies that entries in the "accounts" collection will be dissimilar. This also requires that I have two mongoose schemas for a single collection.</p></li> <li><p>Create an "accounts" collection, have a "type" field and an "accountId" field. In addition to a "student" collection and a "teacher" collection -- the "type" field will indicate which collection the student-specific or teacher-specific fields reside within, and the "accountId" field will indicate exactly which entry the account is matched with.</p></li> </ol> <p>I appreciate all input, criticism or suggestions.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload