P E N C I L
Login
Mongo + Mongoose
  1. Promise with ES6
    mongoose.Promise = Promise;
    with BlueBird
    mongoose.Promise = require('bluebird');
  2. Catch:
    1. Entity.update({a:1},{$set:{b:2}}).then(function(o){}.catch()
    2. .then() returns promise and then we can catch. We cannot catch directly update().catch()
  3. Chain then: then(function () {return promis p1}).then(function(p1){})
  4. Exception reject and it's pass through to the catches.
    Note: resp(err) => show nothing, console.log(err) => does not show stack trae
  5. console.log(err, err.stack)
  6. Create new
    1. new House({attr:value}).save().then()
  7. Add to array
    1. Meetings.update({ "_id": MeetingId }, {$push: { "messages": message }}, function(err, numAffected) { if(err) {//handle error} else { //do something depending on the number of documents affected }});
    2. Use $AddToSet to insert into an array if value does not exist
    3. Tank.findByIdAndUpdate(id, {
          $set: {
              size: 'large'
          }
      }, function(err, tank) {
          if (err) return handleError(err);
          res.send(tank);
      });
    4. Model.findByIdandUpdate()
      Modle.findOneAndUpdate()
    5. Options
      1. new:
      2. upsert
  8. Remove
    1. Model.find().remove()
  9. Select:
    1. Model.find({}).select('field').then(...)
  10. Operator
    1. $in: db.inventory.find( { qty: { $in: [ 5, 15 ] } } )
    2. $ne: {delete: { $ne: true}}  (not equal)
  11. Mongo
    1. db.collection.remove({root: {$not: /true/}})