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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:58:16+00:00 2026-06-08T18:58:16+00:00

I understand that the reduce function is supposed to somewhat combine the results of

  • 0

I understand that the reduce function is supposed to somewhat combine the results of the map function but what exactly is passed to the reduce function?

function(keys, values){
  // what's in keys?
  // what's in values?
}

I tried to explore this in the Futon temporary view builder but all I got were reduce_overflow_errors. So I can’t even print the keys or values arguments to try to understand what they look like.

Thanks for your help.

Edit:

My problem is the following. I’m using the temporary view builder of Futon.

I have a set of document representing text files (it’s for a script I want to use to make translation of documents easier).

text_file:
    id   // the id of the text file is its path on the file system

I also have some documents that represent text fragments appearing in the said files, and their position in each file.

text_fragment:
    id
    file_id   // correspond to a text_file document 
    position

I’d like to get for each text_file, a list of the text fragments that appear in the said file.

  • 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-08T18:58:19+00:00Added an answer on June 8, 2026 at 6:58 pm

    Update

    Note on JavaScript API change: Prior to Tue, 20 May 2008 (Subversion revision r658405) the function to emit a row to the map index, was named “map”. It has now been changed to “emit”.

    That’s the reason why there is mapused instead of emitit was renamed. Sorry I corrected my code to be valid in the recent version of CouchDB.

    Edit

    I think what you are looking for is a has-many relationship or a join in sql db language. Here is a blog article by Christopher Lenz that describes exactly what your options are for this kind of scenario in CouchDB.

    In the last part there is a technique described that you can use for the list you want.
    You need a map function of the following format

    function(doc) {
      if (doc.type == "text_file") {
        emit([doc._id, 0], doc);
      } else if (doc.type == "text_fragment") {
        emit([doc.file_id, 1], doc);
      }
    }
    

    Now you can query the view in the following way:

    my_view?startkey=["text_file_id"]&endkey;=["text_file_id", 2]
    

    This gives you a list of the form

    • text_file
    • text_fragement_1
    • text_fragement_2
    • ..

    Old Answer

    Directly from the CouchDB Wiki

    function (key, values, rereduce) {
        return sum(values);
    }
    

    Reduce functions are passed three arguments in the order key, values and rereduce

    Reduce functions must handle two cases:

    1. When rereduce is false:

      • key will be an array whose elements are arrays of the form [key,id], where key is a key emitted by the map function and id is that of the document from which the key was generated.
      • values will be an array of the values emitted for the respective elements in keys
        i.e. reduce([ [key1,id1], [key2,id2], [key3,id3] ], [value1,value2,value3], false)
    2. When rereduce is true:

      • key will be null
      • values will be an array of values returned by previous calls to the reduce function
        i.e. reduce(null, [intermediate1,intermediate2,intermediate3], true)
        Reduce functions should return a single value, suitable for both the value field of the final view and as a member of the values array passed to the reduce function.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that minifying tries to reduce file size by removing whitespace characters. Sometimes
I understand how to pass an array to a function and let that function
In the function takeNormal() below, there is a line that I don't understand at
I understand that: '\n' // literally the backslash character followed by the character for
I understand that JVM and CLR were designed as stack-based virtual machines. When JIT
I understand that the em measurement is a relative unit for font-size, relative to
I understand that this question may be subjective, this is why I need an
I understand that applications under the same domain name can talk to each other
I understand that storage history is something that is better to keep for vcs
I understand that we can set the various style attributes from code behind using

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.