Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a difference in using orderBy after limit or is it the same thing?

const myScore = 50;

await db.collection("scores")
  .where("score", ">=", myScore)
  .orderBy("score")
  .limit(10)
  .get();

or 

await db.collection("scores")
  .where("score", ">=", myScore)
  .limit(10)
  .orderBy("score")
  .get();

I’m expecting that orderBy will work faster if I use it after limit.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The performance of the two queries is exactly the same. It’s not possible to limit before order. The limit is always taken from the final result, after all filters and orders are applied.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading