`
wsql
  • 浏览: 11715734 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

Optimization Tips | Tip #24: Create indexs that cover your queries

 
阅读更多

如果我们只想返回一个集合中的某些域(类似关系型数据库中的字段),可以包含建立索引的域,MongoDB可以做一些覆盖索引的查询,这永远没有 只是返回索引的数据到客户端.比如:试想我们有这样的索引集:

  1. >db.foo.ensureIndex({"x":1,"y":1,"z":1})

然后,如果我们只查询有索引的域然后只要求返回索引的字段,对于MongoDB载入所有文档是没有理由的.

  1. >db.foo.find({"x":criteria,"y":criteria},
  2. ...{"x":1,"y":1,"z":1,"_id":0})

现在,这个查询只涉及有索引的域.

注意下,查询中包含了_id:0 ,在默认情况下这个_id总是会被返回,但这个不是我们索引的一部分.MongoDB不得不在文档中取到_id.从返回的域中删除它意味着MongoDB只根据之间建索引来返回值.

如果一些查询只返回极少的域的话,考虑下在这些域上都建立索引,这样你可以进行全索引来查询.即使它们不会被查询到,比如,z在上面中没有被查询到,但是它被作为域来返回了(译者解释:也就是说这个z是在可以返回的列中,至于你返不返回是没关系的).



原版书<<50 Tips and Tricks for MongoDB Developers>> 地址:http://oreilly.com/catalog/0636920019893

皮皮书屋下载地址http://www.ppurl.com/2011/05/50-tips-and-tricks-for-mongodb-developers.html

本书的所有翻译地址:http://blog.csdn.net/crazyjixiang/article/category/858638

翻译目的:MongoDB资料国内很少,书就更不必说了,借助对MongoDB的理解为大家做点贡献,如果有翻译有误的地方请指正,不能误入子弟,谢谢!

译者:Crazybaby



分享到:
评论

相关推荐

    JavaScript Patterns

    Technical and architect of YSlow 2.0, the web page performance optimization tool -- JavaScript Patterns includes practical advice for implementing each pattern discussed, along with several hands-on ...

    图像抑制脉冲噪声

    It solves following optimization problem : min_X || Y-X||_1 + lambda ||Dh*X||_1 + lamdba ||Dv*X||_1 + mu ||X||_* X: Hyperspectral image Y: Compressive measurements Dh, Dv: Horizontal and vertical ...

    Convex Optimization for Signal Processing and Communications.pdf

    本资源 为台湾清华大学祁忠勇教授在大陆教授的凸优化课程,已经去过好多高校了,暑期专业选修课程,需要较为扎实的数学基础,如线性代数,微积分,矩阵论,复变函数等等

    Web Performance in Action

    increase rendering speed, decrease the overall footprint of your site, as well as learn how to build a workflow that automates common optimization techniques. You'll also get a look at new ...

    Google Vizier: A Service for Black-Box Optimization

    In this paper we describe Google Vizier, a Google-internal service for performing black-box optimization that has become the de facto parameter tuning engine at Google. Google Vizier is used to ...

    VGG_VOC0712Plus_SSD_300x300_iter_240000.caffemodel

    SSD-caffe已训练好的300x300模型,找国外同学下载的官方模型,基于VOC2007+VOC2012训练的Plus版本,训练了24万轮次,实测VOC2007数据集4952张图片,mAP为90%,实测部分输出如下。同时还有训练好的SSD512模型,同样是...

    50 Tips and Tricks for MongoDB Developers

    Optimization Tips: Speeding up your applications Data Safety Tips: Using replication and journaling to keep data safe—without sacrificing too much performance Administration Tips: How to configure ...

    Ant colony optimization

    Ant colony optimization Introduction and recent trends

    Practical Methods of Optimization Vol2 (Constrained Optimization)

    介绍限制条件上如何求解优化问题。如lagrange multiplier.

    Java.EE.7.Performance.Tuning.and.Optimization.178217642X

    Title: Java EE 7 Performance Tuning and Optimization Author: Osama Oransa Length: 398 pages Edition: 1 Language: English Publisher: Packt Publishing Publication Date: 2014-06-25 ISBN-10: 178217642X ...

    各种算法EvoloPy-master.zip

    The list of optimizers that have been implemented includes Particle Swarm Optimization (PSO), Multi-Verse Optimizer (MVO), Grey Wolf Optimizer (GWO), and Moth Flame Optimization (MFO). The full list ...

    Image Optimization SDK控件

    Image Optimization SDK控件 允许定制和在你的软件中使用我们产品Web Image Guru的功能。 &lt;br&gt; Image Optimization SDK控件 限制一台机器只能由一个开发者使用,为了创建基于客户的软件而不是为了多线程的...

    C++ Optimization

    allows to build complex software that is more efficient than that built using other programming languages. Please note that this language does not guarantee automatically to build efficient software, ...

    Graphs, Algorithms, and Optimization, Second Edition

    "Graphs, Algorithms, and Optimization, Second Edition" English | ISBN: 1482251167 | 2017 | 566 pages | PDF | 10 MB The second edition of this popular book presents the theory of graphs from an ...

    IQA-optimization:知觉优化中IQA模型的比较

    图像质量评估(IQA)模型的感知优化 该存储库使用PyTorch重新实现了现有的IQA模型,包括 , , , , , , , , , 。 注意:复制的结果可能与原始的matlab版本略有不同。 安装: pip install IQA_pytorch ...

    WordPress 3 Search Engine Optimization.pdf

    False positives that aren't penalties 237 Clearing a Google penalty 237 Abandoning your existing domain and starting over 238 Requesting reconsideration following a Google penalty 239 Avoiding ...

    Machine Learning, Optimization, and Big Data: Third International Conference

    The papers cover topics in the field of machine learning, artificial intelligence, computational optimization and data science presenting a substantial array of ideas, technologies, algorithms, ...

Global site tag (gtag.js) - Google Analytics