pymongo sort() limit() different?

廉价感情. 提交于 2019-12-10 17:41:50

问题


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:


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.



来源:https://stackoverflow.com/questions/14182035/pymongo-sort-limit-different

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!