Skip to content
+91-7795206615
|
info@habilelabs.io

  • Home
  • About
  • Services
    • Custom Application Development
    • UI/UX Designing
    • Web Application Development
    • Offshore Product Services
    • Technical Outsourcing
    • ERP Services
  • Company
    • Careers
    • Case Studies
  • Specialization
    • Frontend Frameworks
      • Angular
      • ReactJS
      • VueJS
      • HTML / CSS
      • Javascript /Jquery
      • Bootstrap
      • Material design
    • Backend Frameworks
      • NodeJS
      • Meteor
      • GraphQL
      • Loopback
      • Salesforce
      • Spring Boot
      • Odoo
      • Laravel
    • Database / ORM
      • MySQL
      • PostgreSQL
      • Oracle
      • MongoDB
      • Google Firebase
      • Mongoose
      • Sequelize
      • Hibernate / JPA
    • Languages
      • Java Script
      • Dot Net
      • Java
      • Python
      • C / C++
      • PHP
      • AI / ML
      • Type Script
    • Mobile Frameworks
      • Ionic
      • Native Script
      • Native Android App
      • Native iOS App
      • Google Flutter
      • React Native
  • Blog
  • Hire Us

Lean function for Mongoose query performance

Categories

  • Angular
  • Business Strategies
  • Cloud Services
  • CRM
  • Design Pattern
  • E-commerce
  • ERP Applications
  • Javascript
  • Meteor
  • Mobile development
  • Mongo DB
  • Node JS
  • Odoo
  • Our Partners
  • PHP
  • React
  • SAAS
  • Salesforce
  • SAP
  • Selenium
  • Tech stack Migration
  • Testing
  • UI-UX Design
  • Uncategorized
  • VAPT
  • Visualforce
  • Web Development
  • Web Security

Categories

  • Angular
  • Business Strategies
  • Cloud Services
  • CRM
  • Design Pattern
  • E-commerce
  • ERP Applications
  • Javascript
  • Meteor
  • Mobile development
  • Mongo DB
  • Node JS
  • Odoo
  • Our Partners
  • PHP
  • React
  • SAAS
  • Salesforce
  • SAP
  • Selenium
  • Tech stack Migration
  • Testing
  • UI-UX Design
  • Uncategorized
  • VAPT
  • Visualforce
  • Web Development
  • Web Security
Lean function for Mongoose query performance

As we know that performance is a major issue while working with big data in modern web applications development. So follow this small trick to achieve performance in mongoose query. so let’s learn how to enhance mongoose query performance.

Mongoose Lean chain function that returns a simple JavaScript object, By default mongoose, Find query returns mongoose object with over 1000+ functions with each document.

First, let me explain a very common issue that all we face.

If we want to change the result in mongoose object.

Change in result object
1
2
3
4
Model.find().exec(function(err, data){
// Override data key
// data[0].key = data[0].key * 5
});

Possible solutions can be :

1. With the help of ‘toObject()’ function,  but it doesn’t provide performance. It just converts mongoose document to javascript object.

Example :

1
data [0] = data[0].toObject()

2. Use mongoose Lean chain function

As I mentioned above, the lean chain function provides JavaScript object so the performance of find and find one query execution time will be just twice.

How can I use Mongoose lean chain function?

Syntax
1
2
3
Model.find().lean().exec(function (err, data) {
 
})

When shouldn’t you use this chain function?

If you want to update result document like

user.save()

You shouldn’t use this in this case otherwise save() function will not work.
This small trick will make your query execution fast.

Conclusion

The high performance of MongoDB technology is a big issue while working with big data in modern applications. I hope mongoose lean function article is helpful for performance enhancement.

If you are looking for more tricks for performance read our article about indexing and Query Optimizer that also improves the performance of mongoose query. If you have any problem or query then ask in the comment box, now!

Share with your friends now, if you enjoy this post.

Posted bysurendraApril 13, 2017January 20, 2021Posted inMongo DBTags: Lean function for Mongoose query performance, Mongoose Query, Mongoose query performance

Post navigation


:

Join the Conversation

1 Comment

  1. Yacon Root says:
    August 27, 2017 at 12:58 pm

    Amazing Site. Really enjoyed reading.

    Reply
Leave a comment

Cancel reply

Your email address will not be published. Required fields are marked *

Leave a comment

Recent Posts

  • Cross-Database with Association in Postgres with Sequelize

    Cross-Database with Association in Postgres with Sequelize

  • How can You Improve Your Communication Skills – Effective Tips

    How can You Improve Your Communication Skills – Effective Tips

  • 5 Reasons that Make CRM Software Beneficial for Every Business

    5 Reasons that Make CRM Software Beneficial for Every Business

  • Do Low-Code Solutions have a Future in Web Development?

    Do Low-Code Solutions have a Future in Web Development?

  • A Revenue Management Reset in Consumer Goods

    A Revenue Management Reset in Consumer Goods

  • “Empowering your right-side brain” – Increasing Creativity

    “Empowering your right-side brain” – Increasing Creativity

Talk to our experts now

Have a project or looking for development team? Contact us.

Get a quote

About Us

Habilelabs Private Limited is the ISO 9001:2015 certified IT company, which has marked its flagship in 20+ countries with 100+ projects successfully

Company

  • About
  • Blog
  • Careers
  • Hire Us
  • Privacy Policy

Contact Us

  • +91-9828247415
  • +91-9887992695
  • info@habilelabs.io

Follow Us

Office

  • Habilelabs Private Limited
    4th Floor, I.G.M. School Campus,
    Sec-93 Agarwal Farm, Mansarovar,
    Jaipur, Rajasthan India
    Pin:302020