-------------------------------------------------------------------------------------------------

Lets start with a basic find query in mongoose and observe its execution time.

1
2
3
4
5
6
7
8
Event.find({'schedule.closing': {'$gte': +new Date()}},
        {},
        {limit:20, skip:0}
    ).exec(function (err, events){
 ........
 ........
  }
);

In my last project on Nodejs, I have used the above query to fetch the events from “Event” collection satisfying the given condition. After computing the average execution time, it came out to be 218ms.

Then, I applied lean() in the same query:

1
2
3
4
5
6
7
8
Event.find({'schedule.closing': {'$gte': +new Date()}},
        {},
        {limit:20, skip:0}
    ).lean().exec(function (err, events){
 ........
 ........
  }
);

This time the average execution time came out to be 71ms which is drastically less than the without “lean” version of the same query.

So, you must be wondering what exactly lean() did here?

As described by the mongoose docs, documents returned from queries with the lean option true are plain javascript objects, not Mongoose Documents. They have no save method, getters/setters or other Mongoose magic applied. So in this way the over head attached to the mongoose document is not there in case of lean and we get high performance.

 

High performance find query using lean() in mongoose的更多相关文章

  1. MySQL 之 query cache

    早上一打开网站,就看到了Percona官网发布的最新的关于 mysql query cache的文章: https://www.percona.com/blog/2015/08/07/mysql-qu ...

  2. 解决Mongoose 返回的文档过大导致模板引擎art-template无法渲染的问题,错误-RangeError: Maximum call stack size exceeded

    参考:https://blog.csdn.net/qq_40659195/article/details/88411838 最近尝试用Node写一个小案例,使用到了MongoDB,使用过的人可以知道, ...

  3. mongodb(mongoose-redis-cache)

    在传统的项目中,我们经常会用到缓存来优化数据库的读取,比如java中,我们利用spring的AOP能力,在读写数据库前增加对缓存的操作. 在node与mongodb的项目中也仍然会存在类似问题,本文参 ...

  4. IBM CLI 和 ODBC

    Installing and Configuring DB2 Clients Running CLI/ODBC Programs The DB2 Call Level Interface (CLI) ...

  5. Oracle Purchasing QUESTIONS AND ANSWERS

    Topic Summary Topic: CORRECTIONS: Corrections Topic: DELIVER: Receiving Delivery Topic: DROPSHIP: Dr ...

  6. SQL Server 诊断查询-(5)

    Query #57 Buffer Usage -- Breaks down buffers used by current database by object (table, index) in t ...

  7. mariadb cache1

    http://www.percona.com/blog/2006/07/27/mysql-query-cache/ MySQL Query Cache July 27, 2006 by Peter Z ...

  8. 为什么 EXISTS(NOT EXIST) 与 JOIN(LEFT JOIN) 的性能会比 IN(NOT IN) 好

    前言 网络上有大量的资料提及将 IN 改成 JOIN 或者 exist,然后修改完成之后确实变快了,可是为什么会变快呢?IN.EXIST.JOIN 在 MySQL 中的实现逻辑如何理解呢?本文也是比较 ...

  9. How HipChat Stores And Indexes Billions Of Messages Using ElasticSearch And Redis[转]

    This article is from an interview with Zuhaib Siddique, a production engineer at HipChat, makers of  ...

随机推荐

  1. 通过本地Git部署网站到WebSite

    玩过Azure WebSite(WebApp)的同学应该知道部署网站的方式非常多,今天我要讲的是如果通过本地Git部署网站到WebSite. 1.新建WebSite 创建WebSite非常简单,我这里 ...

  2. springMvc Velocity tool 源码分析

    在公司使用pandoraboot配置了velocity tool,一直不明白官方支持的init方法没有调用,而且不支持velocity tool 1.x版本的定义(1.x和2.x的定义见下面),而另一 ...

  3. 使用 IntraWeb (25) - 基本控件之 TIWRegion

    这应该是 IW 中最重要的容器了, 和它同父的还有 TIWTabControl TIWRegion 所在单元及继承链: IWRegion.TIWRegion 主要成员: property Align: ...

  4. TVS二极管和稳压二极管的区别

    TVS二极管和稳压二极管的区别 TVS管超过它的耐压值后,会瞬间导通短路,反应速度在ns级, 而稳压管是稳压作用的,超过它的稳压值,只要功率不超过它的耐受值,就会稳定在它的稳压值范围内. TVS是瞬态 ...

  5. WinForm多语言版本实战项目演练

    一.课程介绍 关于如何实现“WinForm多语言版本”网上有很多实现技术方案,可以说是“琳琅满目”,"包罗万象".俗话说的好:一千个读者就有一千个哈姆雷特!如果您工作中恰好也遇到这 ...

  6. 委托、Lambda表达式、事件系列02,什么时候该用委托

    假设要找出整型集合中小于5的数. static void Main(string[] args) { IEnumerable<int> source = new List<int&g ...

  7. Delphi 19种反调试检测法

    //使用IsDebuggerPresent这个API来检测是否被调试function FD_IsDebuggerPresent(): Boolean;beginif IsDebuggerPresent ...

  8. 用DELPHI 开发压缩、解压、自解压、加密

    引 言:在日常中,我们一定使用过WINZIP.WINRAR这样的出名的压缩软件,就是我们开发软件过程中不免要遇到数据加密.数据压缩的问题!本文中就这一技术问题展开探讨,同时感谢各位网友的技巧,在我每次 ...

  9. IIS7下配置ASP+ACCESS环境

    先要设置应用程序池(Application Pool)为Classic .NET AppPool,而不是默认的Default AppPool,可以在网站目录里对每个站点设置,也可以在站点进行单独设置. ...

  10. Silverlight for Windows Phone Toolkit

    Silverlight Toolkit 是一套codeplex上的很好的代码库,它里面包含了很多常用的但是Silverlight本身并不包含的控件.文档等内容.现在Silverlight Toolki ...