cbs
cbs copied to clipboard
Sorting/Ordering reports by timestamp in Mongo is not working
In reporting, it is not possible to order by date (timestamp) in an acending order. Only decending. Below is an example of reports ordered by timestamp ascending:
The same problem occurs if we run queries directly against Mongo in Studio 3T:
I got the timestamp from the top 5 documents and they have the same problem as in the frontend. Descending works but ascending is apparently random:
Ascending 637013082263970000 637012111923990000 637012506804020000 637019928394040000 637020792304050000
Descending 637041960614550000 637039299834670000 637035012714420000 637034735494500000 637033988174520000
The timestamp is stored as an array and that might be causing problems for the sorting, but I do not know why descending is working
Timestamp" : [
637013082263970000,
0
]
Sorting should work on timestamp for both descending and ascending order
From MongoDB docs:
With arrays, a less-than comparison or an ascending sort compares the smallest element of arrays, and a greater-than comparison or a descending sort compares the largest element of the arrays.
So the ascending sort doesn't work because the smallest element of the array is always 0 in this case.
MongoDB has it's own Timestamp type, but our timestamp is stored as an array of NumberLong. My guess is this needs a fix from the dolittle framework @woksin @jakhog ? Or can we specify mongo types ourselves?