pymongo sort()的限制()不同? [英] pymongo sort() limit() different?

查看:243
本文介绍了pymongo sort()的限制()不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 1。 db.bios.find()。sort({name:1}).limit(5)
2. db.bios.find()。limit(5).sort({name:1} pre>


  1. 与他们有什么不同?他们是平等的吗?如果第一个做的是:找到所有的文件?它是坏的。

    如果db.bios.find().count()非常大(1000000),哪个进程很快?

  2. 什么是find()默认序列?插入序列?
    Thanks。


解决方案

首先,结果是有限的。

2.为了优化这个,如果这将是一个频繁的查询,考虑在 name 上建立索引。

3. find()的自然顺序通常是插入顺序,但如果文档在创建后被更新,则无法保证。


1. db.bios.find().sort( { name: 1 } ).limit( 5 )
2. db.bios.find().limit( 5 ).sort( { name: 1 } )

  1. What is the different with them? They are equal?
  2. If first one doing: find all documents? it is bad.
    If db.bios.find().count() is very big(1000000), which process fast?
  3. what is find() default sequence? the insert sequence? Thanks.

解决方案

1.These two are equal, sorting will be done first, and then the result will be limited.
2.In order to optimize this, consider having index on name, if this is going to be a frequent query.
3. The natural order for find() is, in general, insertion order, though it is not guaranteed if the documents were updated after creation.

这篇关于pymongo sort()的限制()不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆