{
“2011-01-19 09:41: 00 AM”: “Prototype status application”,
“2011-01-20 09:41:00 AM”: “Play CouchDB”
}
This is a small application, users You can enter his/her status. I want to get the latest status from it. Is this method useful for such an application, or do I have to have a key that defines the sort order?
What is the best way to get the most recent date?
Thank you
If you want to sort by user first, use it as the key by time. If you only want to sort by time, please omit the username as the key.
If you Use date style values:
emit([Date.parse(doc.created_at).getTime(), doc.username], doc);
If you use a lexicographically sorted date format:
emit([doc.created_at, doc.username], doc);
< /p>
I have a nested JSON object for the following key states:
{
“2011-01-19 09:41:00 AM”: ” Prototype status application”,
“2011-01-20 09:41:00 AM”:”Play CouchDB”
}
This is a small application, the user can input him/her The status. I want to get the latest status from it. Is this method useful for such an application, or do I have to have a key that defines the sort order?
What is the best way to get the most recent date?
Thank you
Use view collation and issue a complex key.
If you want To sort by user, use it as the key by time. If you only want to sort by time, please omit the username as the key.
If you use date style values:
emit([Date.parse(doc.created_at).getTime(), doc.username], doc);
If you use a lexicographically sorted date format:
emit([doc.created_at, doc.username], doc);