I have a chat CouchDB which stores records with following format.
type:"chat",
email:"p@g.com",
friendEmail:"m@g.com",
time: [year,month,date,hour,min,sec];
msg:"I'm very good",
I’ve created a view like this
function(doc) {
if(doc.type==="chat" && doc.email && doc.friendEmail){
emit([doc.time,doc.email],doc);
}
}
My questions is how I can get if I want only chat logs by email “p@g.com”?
Side note: I’m using Cradle & NowJS.
The view you’ve created allows you to retrieve by time (and rows with the same time will be ordered by email).
To create a view that allows lookup by email;
and then query with
Note: In neither case is it necessary to copy the whole document into the view. You could instead do emit(key, null) and add &include_docs=true to your query.