A orderBy()
statement has a restriction in that it also serves as a filter for the presence of the specified field. Any documents lacking the given field will be excluded from the result set.
For instance, let's consider a Firestore collection named users
with 3 documents - user1
, user2
, and user3
. Each document includes a field called ignoreUserIds
of type Map, containing values like id : 4
, id2 : 2
, and id3 : 5
for user1
, user2
, and user3
respectively.
users----->
user1---->
ignoreUserIds :
id : 4
user2---->
ignoreUserIds :
id2 : 2
user3---->
ignoreUserIds :
id3 : 5
The queries below will yield their respective outcomes:
db.collection("users").orderBy('ignoreUserIds.id').get() => only user1
db.collection("users").orderBy('ignoreUserIds.id2').get() => only user2
db.collection("users").orderBy('ignoreUserIds.id3').get() => only user3
db.collection("users").orderBy('ignoreUserIds.id4').get() => 0 documents //since there are no documents inside 'users' collection with the field 'ignoreUserIds.id4'.
In your situation, it appears that the field referenced in the orderBy()
statement,
ignoreUserIds.Po0fouROHVQnrV1ZR17L8Tql3OJ2
, is not present in any documents within the
queue
collection. Hence, you're receiving 0 documents.
Furthermore, if you intend to sort the documents based on userIds found within the ignoreUserIds
field, I recommend specifying just ignoreUserIds
in the orderBy clause to achieve this sorting.
Your query should resemble the following -
const snapshot = await this.firestore
.collection("queue")
.orderBy(‘ignoreUserIds’)
.limit(10)
.get();
You can explore this documentation for more insights into the orderBy()
statement and its limitations.