> On Dec 20, 2014, at 4:40 AM, Andrew <[email protected]> wrote:
> 
> Will the sorting on key be able to figure out it is dealing with a timestamp 
> rather than a simple string and sort accordingly ?

No. JSON has no date type; this would be stored as a string and sorted 
accordingly.

You should emit a date format that sorts correctly alphabetically, such as the 
ISO-8601 format that's the de facto standard for JSON. It looks like 
"yyyy-MM-dd'T'HH:mm:ss.SSSZ", i.e. "2014-12-21T17:35:12.874Z". If you're using 
the iOS version of Couchbase Lite, you can use the CBLJSON class to convert 
to/from this format.

It's most efficient if the documents store the dates in this format, but if 
they don't, you can work around it by having your map function do the 
conversion. Just parse the dates from your format and then re-emit them in the 
ISO-8601 format and emit that string as the key.

(Actually if you're going to convert in the map function, it's even more 
efficient to parse the dates into a numeric form like "seconds since 1/1/1970" 
and just emit that number. It's more compact, and faster for the index to sort.)

—Jens

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/1DF247FC-CF19-4D90-8CE6-24B174C9AFB3%40couchbase.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to