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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:58:43+00:00 2026-05-24T05:58:43+00:00

I am using mongoose with nodejs. I am using mapReduce to fetch data grouped

  • 0

I am using mongoose with nodejs. I am using mapReduce to fetch data grouped by a field.So all it gives me as a collection is the key with the grouping field only from every row of database.

I need to fetch all the fields from the database grouped by a field and sorted on the basis of another field.e.g.: i have a database having details of places and fare for travelling to those places and a few other fields also.Now i need to fetch the data in such a way that i get the data grouped on the basis of places sorted by the fare for them. MapReduce helps me to get that, but i cannot get the other fields.

Is there a way to get all the fields using map reduce, rather than just getting the two fields as mentioned in the above example??

  • 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-24T05:58:44+00:00Added an answer on May 24, 2026 at 5:58 am

    I must admit I’m not sure I understand completely what you’re asking.
    But maybe one of the following thoughts helps you:

    either) when you iterate over your mapReduce results, you could fetch complete documents from mongodb for each result. That would give you access to all fields in each document for the cost of some network traffic.

    or) The value that you send into emit(key, value) can be an object. So you could construct a value object that contains all your desired fields. Just be sure to use the exactly same object structure for your reduce method’s return value.

    I try to illustrate with an (untested) example.

    map = function() {
       emit(this.place, 
            {
               'field1': this.field1, 
               'field2': this.field2, 
               'count' : 1 
            });
    }
    
    reduce = function(key, values) {
       var result = { 
           'field1': values[0].field1, 
           'field2': values[0].field2, 
           'count' : 0 };
    
       for (v in values) {
           result.count += values[v].count;
       }
    
       return obj;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using node.js with express. I read out data from MongoDB with Mongoose
Recently I start using MongoDB with Mongoose on Nodejs. When I use Model.find method
Using node.js / expressjs / mongoose / mongoose-auth / everyauth. All versions are up
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using jQuery, what's the best way to automatically initialize a plugin on all current
I'm writing a node.js app using express and mongoose-auth. When I run my app,
I've completed my web app and am using mongoose to serve the php pages.
I'm trying to save myself a lot of queries, I'm using Mongoose as ODM.
I just updated to node 0.5.10 from 0.4.11 and my version of mongoose from
I'm working on a real-time website using Nodejs . Currently, I'm using Redis because

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.