سؤال

Are these two guaranteed to be the same:

collection.limit(10).sort("{score: -1}")

vs

collection.sort("{score: -1}").limit(10)

The second one does a global sort, and returns the top 10. Is the first one guaranteed to do the same, or may it just return 10 sorted records?

Thanks

هل كانت مفيدة؟

المحلول

In normal queries, sort is processed first, then skip, and then limit, no matter in which order you add them to your cursor object.

The aggregation framework will execute the $sort, $skip and limit operators in their order of appearance in the pipeline.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top