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

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. iOS图片设置圆角性能优化

    问题 圆角虽好,但如果使用不当,它就是你的帧数杀手,特别当它出现在滚动列表的时候.下面来看圆角如何毁掉你的流畅度的. 实测 layer.cornerRadius 我创建了一个简单地UITableVie ...

  2. 群晖NAS简介(转)

    Synology 群晖科技(Synology )创立于 2000 年,自始便专注于打造高效能.可靠.功能丰富且绿色环保的 NAS 服务器,是全球少数几家以单纯的提供网络存储解决方案获得世界认同的华人企 ...

  3. CentOS 7安装tunctl

    cat << EOF > /etc/yum.repos.d/nux-misc.repo [nux-misc] name=Nux Misc baseurl=http://li.nux. ...

  4. EF Core数据迁移操作

    摘要 在开发中,使用EF code first方式开发,那么如果涉及到数据表的变更,该如何做呢?当然如果是新项目,删除数据库,然后重新生成就行了,那么如果是线上的项目,数据库中已经有数据了,那么删除数 ...

  5. Reflector_8.3.0.93_安装文件及破解工具

    Reflector_8.3.0.93_安装文件及破解工具 下载地址:http://pan.baidu.com/s/1jGwsYYM   约 8.9MB

  6. Unity声音-音源组件

    音源组件(AudioSource) 音源是场景中在某个位置的发声装置,好像一个喇叭.它播放着音频片段 (Audio Clip). 发出的声音将输出到声音监听器(audio listener),或者声音 ...

  7. Spring Websocket实现文本、图片、声音、文件下载及推送、接收及显示(集群模式)

    相关环境 Nginx,Spring5.x当前(要选择4.0+),tomcat8.x,Quartz 2.x集群(实际运用是Quartz的集群模式和单机模式共存的) 测试面页:http://sms.rey ...

  8. mysql error You must reset your password using ALTER USER statement before executing this statement.

    mysql修改密码Your password does not satisfy the current policy requirements 出现这个问题的原因是:密码过于简单.刚安装的mysql的 ...

  9. MySql、Oracle、MSSQL中的字符串的拼接

    字符串的拼接 1,Mysql 在Java.C#等编程语言中字符串的拼接可以通过加号“+”来实现,比如:"1"+"3"."a"+"b ...

  10. 增加定时检测linux占用内存,及时清理功能

    centos为了提高效率,把部分使用过的文件缓存到了内存里. 如果是这样的话,我又不需要这样的文件性能,那就可以释放.如下两个命令就可以: #sync #echo 3 > /proc/sys/v ...