Automating the document signing process, cause you've got better things to do.
- React.js
- Redux
- Node.js
- MongoDB
- Immutable.js
- Webpack
- SASS
- Flexbox
Why do reference id attributes on models not have a ref
option?
- If the
ref
option is provided. The reference id will not be loaded with with the document. The tradeoff to not usingref
is that mongoose'spopulate
function won't work. See Automattic/mongoose#3020
Why are models being required by import
instead of mongoose.model
in other model files?
- The is a dependency loading issue. We might want to use
ModelB
in a static function ofModelA
, nowModelA
depends onModelB
to be loaded first; but what ifModelA
is loaded beforeModelB
? This would throw aMissingSchema
error. This type of cross dependency can get very complicated very fast - so when using models in other models, it's best toimport
from the direct source.
Why are we using Model.find
+ Model.save
in order to update vs. Model.findOneAndUpdate
in some places?
- Because
Model.save
is a Mongoose method, which means Mongoose Documentpre/post
hooks will be run every timesave
is called (this comes in especially handy inTemplate.js
).Model.findOneAndUpdate
andModel.update
are actually MongoDB methods, so calling these will not invoke Mongoose Document hooks such aspre('save')
. See Automattic/mongoose#2672
**Why are we using res.status(200).json({})
instead of res.status(204).end()
when successfully closing a delete
response?
- This is because we're using the
fetch
. In fetch, data must be converted to JSON usingresponse.json()
. However, if the response is empty,response.json()
throws an error. Therefore it's better to close the response with an empty object instead.response.json()
also fails when the status code is204
, this may be becausefetch
interperates204
as an empty response. Therefore, we have to make due by using200
instead. This is a necessary step to normalize data because there are some instances where we want to send back data after a succesful delete.