Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

orderBy date but have nulls last

I'm querying firestore with:

this.todosCollection = this.afs.collection('todos', ref => ref.where('owner', '==', this.userId). orderBy('due', 'asc'));

The todo items is ordered in ascending order as I want, the problem is that todos without a due date (null) comes first. I want them to come last. Is this possible within the orderBy or other technique?

like image 349
Ola Avatar asked Mar 03 '18 00:03

Ola


1 Answers

That's the way the ordering of nulls is intended to work. The documentation makes this clear, and it can't be changed in the query itself.

If you want to change the ordering, then you will have to manually re-sort the documents on the client to support your preferred ordering. Or, you will have to make two queries, one that includes null and another that does not, then merge the results yourself.

like image 72
Doug Stevenson Avatar answered Sep 30 '22 06:09

Doug Stevenson