Posted By

surfeurX on 11/11/09


Tagged

couchdb


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

kurokikaze


joins in couchdb


 / Published in: JavaScript
 

  1. MAP
  2. function(doc) {
  3. if(doc.doc_type == "User"){
  4. emit(doc._id , doc);
  5. }
  6. else if(doc.doc_type == "Message"){
  7. emit(doc.owner, doc)
  8. }
  9. }
  10.  
  11. REDUCE
  12. function(keys, values)
  13. {
  14. var result = {"messages":[]};
  15. for(var i=0; i<values.length; i++){
  16. if(values[i].doc_type == "User"){
  17. for(v in values[i]){
  18. result[v] = values[i][v];
  19. }
  20. }
  21. else if(values[i].doc_type == "Message"){
  22. result['messages'].push( values[i] );
  23. }
  24. }
  25.  
  26. return result;
  27. }

Report this snippet  

You need to login to post a comment.