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 7505383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:53:34+00:00 2026-05-29T21:53:34+00:00

I am using MongoDB via official Java API. I can store and retrive Long

  • 0

I am using MongoDB via official Java API. I can store and retrive Long values without any extra effort. But when I try to accumulate these values using group() function, JavaScript interpreter converts everything into Doubles and the final result ends up being a Double.

Here is my group command:

{
    ...
    initial: { count: 0 },
    reduce: "function (o, a) { a.count += o.count; }"
}

Is there a way to tell the interpreter that count is in fact a Long? Something like count: 0L or count: Long(0)? Or should I do the accumulation on Java side?

  • 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-29T21:53:38+00:00Added an answer on May 29, 2026 at 9:53 pm

    This is because group command actually run map/reduce, and map/reduce is a javascript. In the javascript default number type is a double, because of this it return doubles.

    So you can probably wrap your numbers with NumberLong(..) if you wanna see long in group command result:

    {
        ...
        initial: { count: new NumberLong(0) },
        reduce: "function (o, a) { a.count += new NumberLong(o.count); }"
    }
    

    Not tested this, but almost sure that it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using mongodb to store information of users. I wanted to create a
I'm using MongoDB with Node.js. Is there any speed advantage to using a MapReduce
I am using mongodb and I have changed the dbpath. Can I just copy
I'm using mongodb and I store datetime in my database in this way for
I am using Mongodb Java driver for my Java client application. it needs to
I'm using mongodb to store image metadata and S3 urls. I would like to
Im using mongodb + java. I tried to insert a new document into an
I am using MongoDB and FuelPHP. I successfully connected to MongoDB and can extract
I'm using MongoDB and official C# driver 0.9 I'm just checking how embedding simple
I'm using mongodb. I'm saving a record with a very long number, but I

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.