Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3216284
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:16:35+00:00 2026-05-17T15:16:35+00:00

I have a MongoDB collection which has a created_at stored in each document. These

  • 0

I have a MongoDB collection which has a created_at stored in each document. These are stored as a MongoDB date object e.g.

{ "_id" : "4cacda7eed607e095201df00", "created_at" : "Wed Oct 06 2010 21:22:23 GMT+0100 (BST)", text: "something" }
{ "_id" : "4cacdf31ed607e0952031b70", "created_at" : "Wed Oct 06 2010 21:23:42 GMT+0100     (BST)", text: "something" }
....

I would like to count the number of items created between each minute, so I can pass the data into Google Charts to generate something like this:

alt text

How do I do this with a map reduce function, or is there a fancy MongoDB aggregate function which I could use instead?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:16:35+00:00Added an answer on May 17, 2026 at 3:16 pm

    Map function should emit a timestamp object, adjusted up to the minute, and a count of 1. The reduce function should sum all the counts:

    map = function() {
        var created_at_minute = new Date(this.created_at.getFullYear(),
                                         this.created_at.getMonth(), 
                                         this.created_at.getDate(), 
                                         this.created_at.getHours(), 
                                         this.created_at.getMinutes());
        emit(created_at_minute, {count: 1});
    }
    
    reduce = function(key, values) { 
        var total = 0;
        for(var i = 0; i < values.length; i++) { 
            total += values[i].count; 
        }
        return {count: total};
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class Document (in a mongodb collection) and persist various sub classes
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have been having a problem where after my mongodb connection to mongohq via
I have a PyMongo newbie question: If collection is a PyMongo Collection and I
I'm running this code: $db = new Mongo(mongodb://user:pw@flame.mongohq.com:27081/dbname); $collection = $db->foobar; $collection->insert($content); I'm trying
What's the best way to store timestamps in MongoDB? Which format is best: #
When I have two MongoDB documents like this... db.test.insert( {value : 10123} ); db.test.insert(
In MongoDB you have a lot of helper methods that do all the basic
I have been using MongoDB and the Ruby driver and Mongoid, and lines db.things.find({j:
I'm thinking about trying MongoDB to use for storing our stats but have some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.