September 2017
Intermediate to advanced
450 pages
11h 24m
English
Sub-documents are effectively just objects embedded directly into your model. Their main advantage is that you can reuse schema definitions from another model, including validations and even indexes for better querying performance.
In our JSON API serializer, we configure our embedded author model to be treated as a relationship. This is useful because, in the event of the same author writing several blog posts, the author object would only be included once. This can be an incredibly efficient way to send data with relationships through your REST API, and is one of the major advantages of using JSON API over just serializing JSON objects from Mongoose into a response:
..."included": [ { "type": "users", "id": "597167ff46a61445e35ce65c" ...
Read now
Unlock full access