saad
saad2y ago

Properly using the .Order()

I was wondering how I could use the order() function on a query, to order my collection by some certain column on my database. It looks like the only parameters the order func takes is ascending or descending, but im not sure what it orders on.
2 Replies
lee
lee2y ago
It orders by the index. And the default index is by_creation_time. So if you want to get the most recently created document, you would do db.query("tbl").order("desc").first(). If you want to order by a field you can define an index in the schema .index("by_score", ["score"]) and then db.query("tbl").withIndex("by_score").order("desc").collect()
saad
saadOP2y ago
tysm

Did you find this page helpful?