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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:08:46+00:00 2026-06-01T23:08:46+00:00

I have a collection in Mongodb like the following: {_id: {thread: abc}, value: 1}

  • 0

I have a collection in Mongodb like the following:

{_id: {"thread": "abc"}, "value": 1}
{_id: {"thread": "cdf"}, "value": 1}
{_id: {"thread": "edf"}, "value": 1}

I tried to map reduce trying to key on value, hoping for an output as follows:

{id_: {"value": 1}, value: 3}

MAP:

function() {
var key = {value : this.value};
emit(key, 1);
};

REDUCE:

function(key, values) {
var sum = 0;
values.forEach(function(value) {
sum += value;});
return sum;
};

EDIT Orignial question: Map Reduce didn’t work is not valid anymore. It was a connection problem and not Map Reduce. Thanks to everyone for the extra bit of information.

unfortunately, that didn’t work and gave an some output as follows:

{u'_id': {u'value': None}, u'value': 1160856.0}

Isn’t it possible to key on an integer value?? I read the map reduce documentation on Mongodb but couldn’t find an info related on the data type of key.

  • 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-01T23:08:47+00:00Added an answer on June 1, 2026 at 11:08 pm

    If you are running your map/reduce from the MongoDB shell you may be running into a feature/issue (opinions vary on that one 😉 ) where the shell converts all integer types to double and stores them as such. There is currently no real workaround other than invoking your m/r from something other than the shell. That said, if I run your m/r I get this :

    {
            "_id" : {
                    "value" : 1
            },
            "value" : 3
    }
    

    Which seems to be what you’re trying to do. I’m not sure if it is or not. Make sure you’re running the latest db version and such.

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

Sidebar

Related Questions

I am trying to figure out this map/reduce system in mongoDB. I have the
I have 10000 documents in one MongoDB collection. I'd like to update all the
I have a collection of articles in MongoDB that has the following structure: {
for example I have collection foo of documents like that: {tag_cloud:[{value:games, count:10}, {value:girls, count:500}]}
I am beginning with mongodb and have a collection with documents that look like
I have a MongoDB collection called employees where there are documents like this: {
I have a MongoDB Collection called Questions which holds JSON Objects that look like
i have a mongoDB collection named col that has documents that look like this
I have a MongoDB collection with objects, the _id property of which is a
I have simple MongoDB collection and I am using SLIM micro-framework to develop a

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.