问题
1. db.bios.find().sort( { name: 1 } ).limit( 5 ) 2. db.bios.find().limit( 5 ).sort( { name: 1 } )
- What is the different with them? They are equal?
- If first one doing: find all documents? it is bad.
If db.bios.find().count() is very big(1000000), which process fast? - 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