I have two docs like this:
{"_id":"doc1","type":"TYPE1","key":"200","create_time":201506231000,"field1":"a","field2":"b"}
{"_id":"doc2","type":"TYPE2","key":"200","create_time":201506241200,"field3":"c"}
My Map function like this:
function (doc,meta) {
if (doc.type == "TYPE1" && doc.key && doc.create_time && doc.field1 && doc.field2){
emit(doc.key,{"create_time":doc.create_time,"type":doc.type,"field": {"field1":doc.field1,"field2":doc.field2}});
} else if (doc.type == "TYPE2" && doc.key && doc.create_time && doc.field3){
emit(doc.key,{"create_time":doc.create_time,"type":doc.type,"field": {"field3":doc.field3}});
}
}
so I can get the following result by key = "200" ( which I want to get)
{"total_rows":2,"rows":[
{"id":"doc1","key":"200","value":{"create_time":201506231000,"type":"TYPE1","field":{"field1":"a","field2":"b"}}},
{"id":"doc2","key":"200","value":{"create_time":201506241200,"type":"TYPE2","field":{"field3":"c"}}}
]
}
Is this function be the correct usage ? or what principle should I following on developing view both couchbase server and couchbase Lite?
and If I want to sort by create_time and using paging , what should I do?