Skip to content

Instantly share code, notes, and snippets.

@drmikeh
Created December 7, 2016 20:57
Show Gist options
  • Save drmikeh/f2a6bcae0ee855a146a45fbe79e9a360 to your computer and use it in GitHub Desktop.
Save drmikeh/f2a6bcae0ee855a146a45fbe79e9a360 to your computer and use it in GitHub Desktop.
SQL vs. NoSQL and Embedded vs. Linked Documents

Mike's Thoughts regarding NoSQL vs. SQL

Wow, lots of discussion here. Here are my thoughts regarding MongoDB, Mongoose, SQL, etc.:

  • In real applications there is no such thing as non-relational data - data will relate to other data and this in inherently a difficult problem to optimize.
  • The trade-off between SQL and NoSQL is between the benefits of ACID vs. the benefits of having a schema-less DB and super high scalability (via partitioning and not having to enforce ACID)
  • Embedded documents should be used very sparingly, otherwise it sets you up for failure.
  • Prefer linking over embedding documents when:
    • the lifecycles differ between the "parent" and the "child" docs (deleting one with/without deleting the other)
    • you need to search or filter for specific child docs
    • you need to share child docs
  • The above means that you will rarely embed any non-trivial docs

The problems I've observed with students learning MongoDB (and Mongoose) is that it can appear to make things really simple but it is just an illusion. You still have to tackle tough problems such as how to define and manage 1-to-1, 1-to-many, and many-to-many relationships between documents.

Mongoose is really not much different than Active Record (expect that AR does have some extra features such as managing both sides of an bidirectional association for you).

The other difficulty with learning MongoDB is with learning all of the async stuff (callbacks, promises) but this is inherent to the async nature of JavaScript I/O, not with MongoDB or Mongoose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment