Sorting Dates in CouchDB Views

前端 未结 1 700
温柔的废话
温柔的废话 2021-01-02 13:34

I have a nested JSON object for the key status below:

{
\"2011-01-19 09:41:00 AM\": \"Prototyping status application\",
\"2011-0

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-02 14:22

    Use view collation and emit a complex key.

    If you first want to sort by user, then by time, use this as key. If you only want to sort by time, omit the username as key.

    If you're using Date-style values:

    emit([Date.parse(doc.created_at).getTime(), doc.username], doc);
    

    If you use a date format that is already sortable lexicographically:

    emit([doc.created_at, doc.username], doc);
    

    0 讨论(0)
提交回复
热议问题