'Firestore: Inequality filter property and first sort order must be the same. Failing where condition and order in different fields. Is this Expected?
I have a collection of documents like this:
{
uid: <UNIQUE_USER_ID>,
lastLoggedIn: <TIMESTAMP_IN_NUMBER>,
...
}
when I try to fetch the data using:
Server.db
.collection(firebasePaths.funfuse_verified_users)
.where('uid', 'not-in', notToIncludeAccounts)
.orderBy('lastLoggedIn', 'desc')
.startAt(startAt)
.limit(limit)
I get an error saying:
Error: 3 INVALID_ARGUMENT: inequality filter property and first sort order must be the same: uid
and lastLoggedIn
Is this a known limitation of firebase or am I doing something wrong ? I want to query all the users which aren't in an array using not-in and then sort those results based on lastLoggedIn timestamp activity.
Solution 1:[1]
As the error message says, in order to be able to use not-in you must first order on the same field:
Server.db
.collection(firebasePaths.funfuse_verified_users)
.orderBy('uid')
.where('uid', 'not-in', notToIncludeAccounts)
.orderBy('lastLoggedIn', 'desc')
.startAt(startAt)
.limit(limit)
This also means that the results will be order first on uid and only then (so if there are multiple results with the same uid value) on lastLoggedIn. If you need them in another order, you will have to resort them in your application code.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Frank van Puffelen |
