Got a document that you don't want to ever show up in the frontend?
You can create a custom `toJSON()` method on your schema, which determines how that document gets serialized to JSON.
#NodeJS#MongoDB
Mongoose 6.5.5 released
🛠️ Avoid applying defaults on insert if nested property set
🛠️ Make applyHooks() and applyMethods() handle case where custom method is set to Mongoose implementation
Full changelog: github.com/Automattic/mongoo…#NodeJS#MongoDB#JavaScript
Mongoose arrays have a convenient `pull()` function that removes values from an array.
No need to `filter()` and reassign, just use `pull()`.
#NodeJS#JavaScript
We make heavy use of Mongoose custom validators in our apps for quick sanity checks.
For example, `age < 200` (sorry Methuselah), `percent > 0 && percent < 1`, etc.
#JavaScript#CodeNewbie
Mongoose's `orFail()` function is great for avoiding repetitive `if (doc == null)` checks.
Makes your query throw an error if no results
Learn more 👉 mongoosejs.com/docs/api/quer…#NodeJS#MongoDB