Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. function query_month(i, data, callback) {
  2. query = M_logs.aggregate([
  3. {
  4. "$match" : {
  5. "time" : {
  6. "$gt" : new Date(now.getFullYear(), i, 1).getTime() / 1000,
  7. "$lt" : new Date(now.getFullYear(), i + 1, 1).getTime() / 1000
  8. },
  9. "from" : "mobile"
  10. }
  11. },
  12. {
  13. "$group" : {
  14. "_id" : "$is_newuser",
  15. "count" : { "$sum" : 1 }
  16. }
  17. }
  18. ]);
  19.  
  20. query.exec(function (err, result) {
  21. if(err) {
  22. console.log('ERR: ' + err);
  23. result = [];
  24. }
  25. if(result.length === 0) {
  26. result = [{ _id: 'n', count: 0 }, { _id: 'y', count: 0 }];
  27. }
  28. data[i] = result;
  29. if(i < now.getMonth()) {
  30. query_month(i + 1, data, callback);
  31. } else {
  32. callback(data);
  33. }
  34. });
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement