JumpStart – CRUD, Testing CRUD

CRUD
note: __v is versioning, only updates on .save()
.save(), .find(), .where, findByIdAndUpdate(), findOneAndDelete()

Queries are Not Promises

Mongoose queries are not promises. They have a .then() function for co and async/await as a convenience. However, unlike promises, calling a query’s .then() can execute the query multiple times.

Testing CRUD

Schema Validation
validates only on .save()
for the rest of the methods, set runValidatorsoption to true

Use .delete instead of .remove by default
mongoose implementation of update() behaves like patch
mongoose unique is not a validator

Middleware hooks (pre save, etc)

Virtuals
virtual temp props that do not persist (like fullName constructed from firstName and lastName)

personSchema.virtual(‘fullName’).get(function(){

return this.name.first + ‘ ‘ + this.name.last}

Populate

sub documents
.populate(‘author’)

 

Extra
12 factor app
object calisthenics

Leave a comment

Design a site like this with WordPress.com
Get started