Hi everybody…I’m not pretty sure if I understand well collated views, I only could found a couple of articles about it…I was trying this in the last night…my idea: create documents which are related to messages, every essage has an author and could have many destinataries (which are saved as an array)
i.e
{
“type”: “direct_message”,
“message”: “hello darling”,
“from”: “mark”,
“to”: [
“marta”,
“juana”,
“pedro”
]
}
now…my view is this
function(doc,meta){
if(doc.type==“direct_message”){
doc.to.map(function(name){
emit([doc.from,name,meta.id])
})
}
}
this works pretty fine…I get
[“mark”,“juana”,“1”]
1 null
[“mark”,“marta”,“1”]
1 null
[“mark”,“pedro”,“1”]
now…I whish explore all messages posted by “mark”
I use startkey [“mark”,“a”,1]
endke [“mark”,“Z”,99999999]
the key for the meta.id is very ugly…I use 99999 but I suppose than would be a better way…however works good, the Z in the endkey also works as expected (“to” only use lowcase so Z is a good limit) now I would prefer than couchbase had something like redis where I can use * but is ok
the problem is when I which get all messages for a specific user…I tried this
startkey [“a”,“juana”,1]]
endke [“Z”,“juana”,99999999]
this return
[“juana”,“marta”,“3”]
3 null
[“mark”,“juana”,“1”]
1 null
[“mark”,“marta”,“1”]
1 null
[“mark”,“pedro”,“1”]
1 null
[“marta”,“paco”,“2”]
2 null
is it ok?..I’m using collate views in a wrong way??
2 point: I was looking for n1ql and seems pretty nice, would be a good idea use
n1ql instead of views?..exist a performance penalty or any disadvantage about using
n1ql over views??..thanks!!.