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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:58:33+00:00 2026-06-02T18:58:33+00:00

I’m having some issue getting what seems like a fairly straight-forward problem solved in

  • 0

I’m having some issue getting what seems like a fairly straight-forward problem solved in CouchDB 1.01. My data is basically a log of drugs despensed from 30 odd clinics with some basic data about the drug and a timestamp. I’m passing a fairly ordinary group of objects as a map result into reduce in the pseudo-form:

Key:ClinicName, Value:{"vaccine":DrugType, "stamp":TimeStamp}

The aim of my reduce function is to allow a quick reference of the amounts of each type of drug dispensed.

Map

function(doc) {
   if(doc.type=="dose"){
    emit(doc.clinicName, {"vaccine":doc.vaccine,"stamp":doc.timestamp});
   }
}

Reduce

function(keys, values){
  var indexes = Object.keys(values);
  var vCount = new Object;
  for (var c in indexes){
    var val = values[c]
    var vname = val.vaccine
    if(vCount.hasOwnProperty(vname)){
      vCount[vname] = vCount[vname] + 1;
    }
    else{
      vCount[vname] = 1;
    }  
  }
  return vCount;
}

This works perfectly when I have with ?key= a specific ClinicName as long as descending=false and group=true. As soon as set descending to true, my results are cut off about halfway through.

Two questions:

  1. Why should the result order matter for the reduce function? With reduce off, the results are the same forwards and backwards.
  2. I’d read somewhere that if your reduction doesn’t provide a single scalar, you’re probably doing it wrong. If strange behavior aside this is a poor approach, what’s the right way to present this sort of data from a log-style data source?
  • 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-02T18:58:35+00:00Added an answer on June 2, 2026 at 6:58 pm

    If you want to know the amount (count) of vaccines per clinic, then you need that in the key.

    // pseudo-form
    Key:[ClinicName, DrugType], Value:{"stamp":TimeStamp}
    

    Next, your reduce “function” can simply be the string "_count".

    With this, you can set ?group_level=2 and get one row per clinic per vaccine, with a sum of all doses dispensed. This may not be relevant to you, but you get for free the ability to count doses (of all drugs) per clinic with ?group_level=1.

    To get the total count of vaccines across all clinics, that view must be keyed on the drug only.

    // pseudo-form
    Key:DrugType, Value:{"stamp":TimeStamp}
    

    The primary point is that reduce must always work on rows that are adjacent, next to each other in the map output. Then you can use ?group_level or startkey/endkey to get meaningful results.

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

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words

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.