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

  • Home
  • SEARCH
  • 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 8695245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:59:00+00:00 2026-06-13T00:59:00+00:00

Following official mongodb docs ( http://docs.mongodb.org/manual/use-cases/pre-aggregated-reports/#log-an-event ) i’m trying to setup the same in

  • 0

Following official mongodb docs ( http://docs.mongodb.org/manual/use-cases/pre-aggregated-reports/#log-an-event ) i’m trying to setup the same in nodejs + mongoose but there is a problem that i cannot figure out.

Problem is in $inc key : value, i cannot compute dynamic key like its already done in python:

 update = { '$inc': {
            'hourly.%d' % (hour,): 1,
            'minute.%d.%d' % (hour,minute): 1 } 
 }

My code looks like :

var daily_schema = mongoose.Schema({
    _id: 'string',
    metadata: {
        date: { type: 'date', default: Date.now() },
        site: 'string',
        page: 'string'
    },
    hourly: 'object',
    minute: 'object'    
});

var daily_stats = mdb.model('hits', daily_schema);

var date = new Date();
var day = date.getDate();
var hour = date.getHours();
var minute = date.getMinutes();
var year = date.getFullYear();

daily_stats.update({
    _id : year + '/' + data.xid + '/' + data.url,
    metadata : {
        date : date,
        site : data.xid,
        page : data.url
    }
    },
    {
    $inc: { 
        'hourly.' + hour : 1, // (python: 'hourly.%d' % (hour,): 1,) how about javascript?
        'minute.' + hour + '.' + minute : 1
    }
    },
    { upsert: true }, function(err) {
        if (err) { console.log("daily_stats:upsert:error"); console.log(err) } else {
        console.log("daily_stats:upsert:ok");
    }           
    }
);

Please give me a hint how this can be done in javascript?

Best regards & thanks to all!

  • 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-06-13T00:59:01+00:00Added an answer on June 13, 2026 at 12:59 am

    You need to first build up your $inc object programmatically and then include that in your update call.

    var inc = { $inc: {} };
    inc.$inc['hourly.' + hour] = 1;
    inc.$inc['minute.' + hour + '.' + minute] = 1;
    
    daily_stats.update({
        _id : year + '/' + data.xid + '/' + data.url,
        metadata : {
            date : date,
            site : data.xid,
            page : data.url
        }},
        inc,
        { upsert: true }, function(err) {
            if (err) { console.log("daily_stats:upsert:error"); console.log(err) } else {
            console.log("daily_stats:upsert:ok");
        }           
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

By following the official instructions http://www.mongodb.org/display/DOCS/Quickstart+Unix and this post http://blog.phy5ics.com/2010/03/27/installing-mongodb-on-mediatemple-dv/ I've just about managed
the following lines are from the official jQuery website <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js></script> <script>!window.jQuery && document.write('<script
Wow I've been struggling with this for whole day, following the official ruby on
The following code snippet is from The Official GNOME 2 Developer's Guide : GMemChunk
I installed RVM from scratch following the installation guide on the official website. I
Following chunk html code works as expected: <iframe src=http://www.amazon.com/></iframe> But when trying embed inner
I've been testing out the official MongoDB C# Driver with a replica set of
The official site shows the following function square = (x) -> x * x
The following line of code comes from the official dialog/#modal-form example allFields = $(
Official problem: Write Java method to perform recursive descent parse of the following production:

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.