Why are Mongoose (MongoDB ODM) lean queries faster than normal queries?

Write your answer…

The main reason is because the objects returned when using lean() are plain Javascript objects. On the other hand objects returned with a normal query have extra Mongoose magic attached to them, like save function, getters and setters and other things.

The performance gain is in the difference of a plain JSON object versus a Mongoose object with all the fancy things it has. See http://mongoosejs.com/docs/api.html#query_Query-lean

You can take advantage of this, if the operation you are running is just to read data, then use lean, if you need extra Mongoose functionality to edit the object and then save it, then call a regular query.

Here is an interesting article about performance tweaks for mongoose http://codeandcodes.com/2014/07/31/mongodb-performance-enhancements-and-tweaks/

Reply to this…