user10412277
user10412277

Reputation:

Firestore: How to use order by field of object of array

I have a database like this.

enter image description here

How can I order by the timestamp field in the array?

.orderBy("received[0].timestamp", "desc")

Upvotes: 4

Views: 2168

Answers (1)

Ricardo Smania
Ricardo Smania

Reputation: 3149

You cannot directly. But what you can do is create a new field on your document called firstTimestamp or something similar, and then replicate the timestamp from the first element of the array into that field. You can do that in a Cloud Function or in your frontend/backend code. That way you can sort or filter by that field.

Upvotes: 4

Related Questions