Mongoose __v property – hide?

You can disable the “__v” attribute in your Schema definitions by setting the versionKey option to false. For example: var widgetSchema = new Schema({ … attributes … }, { versionKey: false }); I don’t think you can globally disable them, but can only do it per Schema. You can read more about Schema’s options here. … Read more

Why Mongoose doesn’t validate on update?

As of Mongoose 4.0 you can run validators on update() and findOneAndUpdate() using the new flag runValidators: true. Mongoose 4.0 introduces an option to run validators on update() and findOneAndUpdate() calls. Turning this option on will run validators for all fields that your update() call tries to $set or $unset. For example, given OP’s Schema: … Read more

How do I limit the number of returned items?

In the latest mongoose (3.8.1 at the time of writing), you do two things differently: (1) you have to pass single argument to sort(), which must be an array of constraints or just one constraint, and (2) execFind() is gone, and replaced with exec() instead. Therefore, with the mongoose 3.8.1 you’d do this: var q … Read more