Created
          April 10, 2014 05:06 
        
      - 
      
- 
        Save keepcosmos/10344110 to your computer and use it in GitHub Desktop. 
    mongo db group by count
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | db.messenger_rooms.group({ | |
| keyf: function(doc){ | |
| var date = new Date(doc.created_at); | |
| date.setHours(date.getHours() + 9); | |
| var dateKey = (date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()); | |
| return {'day':dateKey}; | |
| }, | |
| cond: {created_at: {$gte: ISODate("2014-04-01"), $lte: ISODate("2014-04-03")}}, | |
| initial: { count: 0, reserved_count: 0}, | |
| reduce: function(doc, aggregator){ | |
| aggregator.count += 1; | |
| if(doc.reservation_status !== undefined && doc.reservation_status !== null) aggregator.reserved_count++; | |
| } | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment