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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:24:44+00:00 2026-06-05T17:24:44+00:00

My docs contain lists of errors. I have a view which counts the number

  • 0

My docs contain lists of errors.
I have a view which counts the number of docs with a specific error, and an average of how many errors a doc with a given error has.

Map

function (doc) {
var i;
for (i = 0; i < doc.errors.length; i = i + 1){
    emit([doc.errors[i], doc.flummery], [1, doc.errors.length])
}

}

Reduce

function (key, values, rereduce) {
var avg = [];
var cnt = [];
var i;
for (i = 0; i < values.length; i = i + 1) {
    avg.push(values[i][1]);
    cnt.push(values[i][0]);
}
return [sum(cnt), eval(avg.join("+")) / avg.length]

}

I have read many times that the use of eval() is the path to madness, but I can’t think of any way that it could really trip me up here. Is eval() safe in couchdb views?

Note that Oleg came up with the obvious answer, which is “don’t do that, couchdb gives you a sum() function”. It is obvious in this situation that eval() is not needed. However, should I ever require it, is it safe to use given that I’ll have good control over my inputs?

  • 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-05T17:24:46+00:00Added an answer on June 5, 2026 at 5:24 pm

    Can’t you use sum(avg) / avg.length instead?

    eval have obvious drawback of calling full power of compiler: it is very resource heavy and introduces a big security hole unless you carefully sanitize your input.

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

Sidebar

Related Questions

I have gone through the tutorial for component development at http://docs.joomla.org/Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.7_-_Part_06 . While the
So I've read the official JUnit docs, which contain a plethora of examples, but
I have a bunch of Word docs which were saved as filtered html. The
I just started using YUI3 Test module (http://yuilibrary.com/yui/docs/test/). I have testcases with many asserts
The docs on this are pretty shoddy. There are a number of events you
http://docs.python.org/3.0/whatsnew/3.0.html says it lists whats new , but in my opinion, it only lists
According to the Django testing docs, the Django client Response object contains 'templates', which
I have a Document Library on SharePoint which hosts documents of different types and
You often need View in View. For example, a client that has many phone
The docs says that ancestor will apply a filter of given ancestor being somewhere

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.