原文: http://www.tothenew.com/blog/high-performance-find-query-using-lean-in-mongoose-2/
-------------------------------------------------------------------------------------------------
EmailTwitterFacebookLinkedInGoogle+

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. Mongoose属性

    1.Mongoose() Mongoose类的构造函数.一个实例. Mongoose.prototype.Collection() Mongoose.prototype.Connection() Mo ...

  2. mongoose中通过-id查询的方法

    第一种方法: var mongoose = require('mongoose'); var id = mongoose.Types.ObjectId('4edd40c86762e0fb1200000 ...

  3. Adaptive Query Execution: Speeding Up Spark SQL at Runtime

    This is a joint engineering effort between the Databricks Apache Spark engineering team - Wenchen Fa ...

  4. SDU信息门户(5)——教务系统学生功能

    2021SC@SDUSC 目录 引言 代码分析 总结 引言 在SDU信息门户的教务系统中学生功能占据着重要的地位,在教务系统各个子功能中大部分都涉及到学生信息的添加修改,学生所选课程信息的获取以及上传 ...

  5. LBS 基于位置的服务

    LBS隐私保护的一些看法 2016年12月07日 13:50:25 阅读数:2214 标签: 物联网隐私lbs 更多 个人分类: 分布式虚拟化 版权声明:本文为博主原创文章,转载请注明出处,查看原文章 ...

  6. Materialized Views

    2019独角兽企业重金招聘Python工程师标准>>> A materialized view provides access to table data by storing th ...

  7. [官方] mysql 性能优化文档(中英文自译)

    大家好,我是烤鸭: 根据官方文档翻译并精简部分内容.建议有时间的朋友下载原版查看,全文106页pdf,快的话1-2天就能看完.自己翻译的有些地方可能不完整,欢迎指正. 官方pdf下载,需登录: htt ...

  8. t-sql 使用正则表达式_如何在T-SQL查询中使用可扩展表达式; 性能优势和实例

    t-sql 使用正则表达式 挑战 (The challenge) One of the main tasks of a SQL Server database administrator is per ...

  9. sql server 性能_SQL Server硬件性能调整

    sql server 性能 SQL Server Performance Tuning can be a difficult assignment, especially when working w ...

最新文章

  1. PHP获取客户端的网卡mac物理地址
  2. Linux: I/O多路转接之poll(有图有代码有真相!!!)
  3. NDK 在 Android studio如何使用(Android studio NDK)
  4. 【持久化框架】SpringMVC+Spring4+Mybatis3集成,开发简单Web项目+源码下载
  5. laravel 淘宝 NPM 镜像
  6. maven 单独构建多模块项目中的单个模块
  7. u盘安装linux 提示no such device_IGH EtherCAT 开源主站安装及测试
  8. Python稳基修炼的经典案例4(计算机二级、初学者必须掌握的例题)
  9. 心语收集13:有时候我真想忘了你,只记得这个世界,然而,我常常忘了整个世界,只记得你。...
  10. 【java面试经(架构师设计师)-第4课】java基础常识
  11. uniapp 动态设置导航栏标题 副标题 背景图片 web-view
  12. 通过AWS创建无服务器的动态DNS系统
  13. 【离散数学】单射、满射、双射、映射的合成与逆映射
  14. RL 笔记(3)PPO(Proximal Policy Optimization)近端策略优化
  15. 老字号品牌营销杂志老字号品牌营销杂志社老字号品牌营销编辑部2022年第23期目录
  16. 如何根据原理图画封装_如何快速设计元器件原理图库和PCB封装库?
  17. CC2530内部结构图
  18. H+ Se7en WebUI
  19. 跟着sleep看jvm线程变化
  20. x7plus升级Android,vivo X7 Plus原版系统刷机包_X7Plus最新全量升级包更新下载

热门文章

  1. java21天打卡day20-集合
  2. 软件测试面试题小结(一)
  3. rust怎么建柱子_小报:捷达VS5安全带卡扣向里?敲B柱?怎么掰回来? 第191220期...
  4. 基于python的音频播放器_基于python实现音乐播放器代码实例
  5. 保研论坛app服务器网站,保研论坛官网版app
  6. linux+patches工具_[经验分享] 最简安装: ubuntu+gnome3+常用工具
  7. 无锡太湖学院计算机科学与技术宿舍,无锡太湖学院宿舍怎么样
  8. 两个3*3*n旋转矩阵在第三维相乘
  9. sas 怎么连接mysql_sas连接MySQL
  10. AI学习笔记(十一)CNN之图像识别(上)