Guest

Untitled

By: a guest on Jan 28th, 2012  |  syntax: None  |  size: 0.64 KB  |  hits: 35  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. function(doc) {
  2.         if (doc.type == 'user') {
  3.                 emit(doc._id, doc.username);
  4.         } else if (doc.type == 'picture' && doc.published_datetime > 1) {
  5.                 delete doc.exif;
  6.                 emit(doc.user_id, doc);
  7.         }
  8. }
  9.  
  10. function(key, values) {
  11.         var dump = [], pics = [];
  12.         for (var x = 0, y = values.length; x < y; x++) {
  13.                 var doc = values[x];
  14.                 if (doc.type == 'user') {
  15.                         dump.push(doc);
  16.                 } else if (doc.type == 'picture') {
  17.                         pics.push(doc);
  18.                 }
  19.         }
  20.         pics.sort(function(a, b) {
  21.                 return a.published_datetime < b.published_datetime;
  22.         });
  23.         for (var x = 0; x < 10; x++) {
  24.                 var doc = pics.shift();
  25.                 if (doc) {
  26.                         dump.push(doc);
  27.                 }
  28.         }
  29.         return dump;
  30. }