quering couchbase views by secondary index and ordering results -
i have documents in bucket:
{ type: "post", author: "1", subject: "s1", timestamp: 11} { type: "post", author: "1", subject: "s2", timestamp: 12} { type: "post", author: "2", subject: "s3", timestamp: 9 } { type: "post", author: "3", subject: "s4", timestamp: 10} { type: "post", author: "4", subject: "s5", timestamp: 14} { type: "post", author: "5", subject: "s6", timestamp: 11} i have got view:
function(doc, meta) { if(doc.t === 'post') { emit([doc.timestamp, doc.author]); } } it gives me:
[11, "1"] [12, "1"] [9, "2"] [10, "3"] [14, "4"] [11, "5"] i want select posts of specific users ["2","3","5"] ordered timestamp. mean "get newest posts of users". possible do?
i re-organize data: assuming authors unique, keep document each author , save posts list within doc.
doc name: "author:1" doc: { 'posts':[{'subject':'s1','body':'this body1'}, {'subject':'s2','body':'this body2'}] } the trick maintain order within list of posts. view can pull last item in list of posts if want latest post.
Comments
Post a Comment