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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:29:36+00:00 2026-06-15T09:29:36+00:00

I have the following layout: { URL: http://someurl.de, plugins: { HTTPServer: { os: [

  • 0

I have the following layout:

{
    "URL": "http://someurl.de",
    "plugins": {
        "HTTPServer": {
            "os": [
                "FreeBSD"
            ],
            "string": [
                "Apache/2.2.21 (FreeBSD) mod_ssl/2.2.21 OpenSSL/0.9.8q DAV/2 PHP/5.3.8 with Suhosin-Patch"
            ]
        }
    }
}

From which I want to get the count of the unique items stored in plugins.HTTPServer.string. All the MapReduce examples however just refer to single level documents. As I understand the examples, you have to emit the data in the map function (or choose data you want to extract) and then reduce is used to further process the results. I think my problem is during the mapping stage – that I need to get access to the string value above that reads: “Apache/2.2…”

As I’ve only spent the last day in MongoDB, forgive my ignorance if I’m not asking the right questions here. Am I headed in the right direction? I know I can use distinct = db.coll.distinct(‘plugins.HTTPServer.string’), but I’d like to get this done with MapReduce.

map = function() {
  server = this.plugins.HTTPServer.string
  emit({server : this.server}, {count: 1});
}

reduce = "function(key, values) {
  var count = 0;

  values.forEach(function(v) {
    count += v['count'];
  });

  return {count: count};
}"
  • 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-15T09:29:37+00:00Added an answer on June 15, 2026 at 9:29 am

    You’ve got a few problems:

    1. this.server in the map funtion’s emit should just be server
    2. In your documents, the "string" field is an array, not a single string, so you’re emitting the array as your key which probably isn’t what you want.
    3. You’ve got stray " characters in your reduce function.

    Try this instead:

    var map = function() {
      if (this.plugins && this.plugins.HTTPServer && this.plugins.HTTPServer.string) {
        this.plugins.HTTPServer.string.forEach(function(server) {
          emit({server: server}, {count: 1});
        });
      }
    }
    
    var reduce = function(key, values) {
      var count = 0;
    
      values.forEach(function(v) {
        count += v['count'];
      });
    
      return {count: count};
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a URL string in the following format. http://myserver.com/_layouts/feed.aspx?xsl=4&web=%2F&page=dda3fd10-c776-4d69-8c55-2f1c74b343e2&wp=476f174a-82df-4611-a3df-e13255d97533 I want to replace
I have the following layout: <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:background=@drawable/aussie_bg_big > <ImageView android:id=@+id/titleImage android:layout_width=wrap_content
I have the following XML layout for a ListActivity. <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I have the following XML layout file, HELPME.XML <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent
I have the following code layout <script src=http://some.javascript/file.js></script> // This should load first <script
I have the following layout in my page (simplified) <h:form> <h:commandButton action=#{bean.save} value=Save/> <rich:tabPanel
I have the following layout for my mvc project: /Controllers /Demo /Demo/DemoArea1Controller /Demo/DemoArea2Controller etc...
I have the following layout defined for one of my Activities: <?xml version=1.0 encoding=utf-8?>
I have the following layout : And following code : public class MailSenderActivity extends
This is maddening. I have the following XML layout: <FrameLayout android:layout_width=fill_parent android:layout_height=wrap_content android:background=@drawable/shadow android:focusable=true

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.