Flutter Isar Database — part 5 — Advanced Querying

Tomic Riedel
5 min readAug 25, 2022

In the last article, we dealt with how to filter the data we query. Today we will look at advanced querying. This includes 8 topics that we will discover today. Bigger topics are sorting, unique values, and offsets & limits.

If you are new to this series, check out this list.

You can find the whole source code provided in this article here.

Happy reading!


Okay, let’s first take a look at sorting. There are four methods to sort your results: .sortBy(), .sortByDesc(), .thenBy() and .thenByDesc(). SortBy… means, that you first sort by this value. If two of them are equal (Let’s say you have two times the same shoe model in your database), then you can sort this by something other (for example the size). This could look like this:

This works fine but is a very expensive operation. In the last article, we learned about Indexes. We can use them here too, to sort our output. This is especially important if we have big databases with millions of objects.

Where clause sorting

If you only use one index in your query, the results are already sorted. This saves very much computation time:

If you don’t want to use where clauses, but also want to use the benefits of implicit sorting, you can use any():

Tip from the official documentation:

If you need the results to be sorted, consider using an index for that purpose. Especially if you work with offset() and limit(). [We will discuss Offset & Limit later.]

(Source: https://isar.dev/queries.html#sorting)

Unique values



Tomic Riedel

Flutter, Dart & Appwrite Developer | Livelong learner | Happy about sharing my knowledge