I’m using v.2.0 of couchbase-lite-android and I save timestamp (Java Long) for date and want to group records by DAY.
How can I write for couchbase the same SQL request like this one for MySQL:
SELECT date,*
FROM Table
GROUP BY DATE_FORMAT(date, “%m-%y-%d”)
ORDER BY YEAR(date) DESC, MONTH(date) DESC, DAY(date) DESC
We support simple groupBy option in CBM 2.0. We do not have a way of returning the aggregated results for each date key as you want. I have made a simplifying assumption here about the way the Date is stored (It is split into its components). We do not have date manipulation functions of the kind you specify
Actually, looking at your code, what you’d need is to store the date as a string in %yyyy-%mm-%dd form. Then you can just group by that property and sort by it in descending order.
I don’t think its a good idea. If I save date like String %yyyy-%mm-%dd I will lose timezone information…
I prefer to save timestamp (Long) in DB and create String index only. If this is possible?
You can store the date in other forms as well if you need to. I’m just saying that storing a property with the date in that form will allow you to do the query you want.