You mean, change view like this?:
function (doc, meta) {
if (meta.type == "json" && doc.type == "fileActivity") {
// Check if doc is JSON
emit(doc.createdAt, {
'docId': doc.docId,
'createdAt': doc.createdAt,
'updatedAt': doc.updatedAt,
'file': doc.file,
'subject': doc.subject,
'message': doc.message,
'fromUserName': doc.fromUserName,
'toUserName': doc.toUserName,
'read': doc.read
});
} else {
// do something with binary value
}
}
but then I can only search by createdAt, and I need to look across the field toUserId and sort by createdAt.