High performance find query using lean() in mongoose
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的更多相关文章
- MySQL 之 query cache
早上一打开网站,就看到了Percona官网发布的最新的关于 mysql query cache的文章: https://www.percona.com/blog/2015/08/07/mysql-qu ...
- 解决Mongoose 返回的文档过大导致模板引擎art-template无法渲染的问题,错误-RangeError: Maximum call stack size exceeded
参考:https://blog.csdn.net/qq_40659195/article/details/88411838 最近尝试用Node写一个小案例,使用到了MongoDB,使用过的人可以知道, ...
- mongodb(mongoose-redis-cache)
在传统的项目中,我们经常会用到缓存来优化数据库的读取,比如java中,我们利用spring的AOP能力,在读写数据库前增加对缓存的操作. 在node与mongodb的项目中也仍然会存在类似问题,本文参 ...
- IBM CLI 和 ODBC
Installing and Configuring DB2 Clients Running CLI/ODBC Programs The DB2 Call Level Interface (CLI) ...
- Oracle Purchasing QUESTIONS AND ANSWERS
Topic Summary Topic: CORRECTIONS: Corrections Topic: DELIVER: Receiving Delivery Topic: DROPSHIP: Dr ...
- SQL Server 诊断查询-(5)
Query #57 Buffer Usage -- Breaks down buffers used by current database by object (table, index) in t ...
- mariadb cache1
http://www.percona.com/blog/2006/07/27/mysql-query-cache/ MySQL Query Cache July 27, 2006 by Peter Z ...
- 为什么 EXISTS(NOT EXIST) 与 JOIN(LEFT JOIN) 的性能会比 IN(NOT IN) 好
前言 网络上有大量的资料提及将 IN 改成 JOIN 或者 exist,然后修改完成之后确实变快了,可是为什么会变快呢?IN.EXIST.JOIN 在 MySQL 中的实现逻辑如何理解呢?本文也是比较 ...
- 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 ...
随机推荐
- C#中四种常用集合的运用(非常重要)
C#中4个常用的集合 1.ArrayList ArrayList类似于数组,有人也称它为数组列表.ArrayList可以动态维护,而数组的容量是固定的. 它的索引会根据程序的扩展而重新进行分配和调整. ...
- STM32定时器级联 -- AN2592
Master configuration When a timer is selected as a master timer, the corresponding trigger output si ...
- 采用模拟账号读取Exchange server未读邮件的注意事项(链接邮箱问题)【转】
最近做项目碰到Exchange中,用EWS API方法读取的未读邮箱(ConnectingIdType.PrincipalName设置该属性的方法)附带代码部分: 核心代码 using Microso ...
- [EF]数据上下文该如何实例化?
摘要 之前使用过一段Nhibernate,最近在尝试EF做项目,但对DbContext的实例化,有点困惑,发现和Nhibernate有不同.这里将查找的例子,在这里列举一下. 资料 在EntityFr ...
- Unity3D实践系列03,使用Visual Studio编写脚本与调试
在Unity3D中,只有把脚本赋予Scene中的GameObject,脚本才会得以执行. 添加Camera类型的GameObject. Unity3D默认使用"MonoDevelop&quo ...
- 延迟调用或多次调用第三方的Web API服务
当我们调用第三方的Web API服务的时候,不一定每次都是成功的.这时候,我们可能会再多尝试几次,也有可能延迟一段时间再去尝试调用服务. Task的静态方法Delay允许我们延迟执行某个Task,此方 ...
- 【mybatis】mybatis进行批量更新,报错:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right
使用mybatis进行批量更新操作: 报错如下: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an erro ...
- Ioc:autofac lifetime scope.
During application execution, you’ll need to make use of the components you registered. You do this ...
- ibatis.net:第二天,Hello,World ?
背景 本文的内容全部来自于官方的文档,此处仅仅为了强化记忆. 项目结构 Properties.config <?xml version="1.0" encoding=&quo ...
- WebRTC 基于GCC的拥塞控制(下)
转自;http://blog.csdn.net/ljh081231/article/details/79152578 本文在文章[1]的基础上,从源代码实现角度对WebRTC的GCC算法进行分析.主要 ...