Reputation: 2285
I have a chat CouchDB which stores records with following format.
type:"chat",
email:"[email protected]",
friendEmail:"[email protected]",
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 "[email protected]"?
Side note: I'm using Cradle & NowJS.
Upvotes: 4
Views: 398
Reputation: 4631
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;
emit(doc.email, doc);
and then query with
[email protected]
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.
Upvotes: 2