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

  • Home
  • SEARCH
  • 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 7442739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:13:19+00:00 2026-05-29T11:13:19+00:00

I have a document which includes a subdocument: { _id : ObjectId(XXXXX), SearchKey :

  • 0

I have a document which includes a subdocument:

{
    "_id" : ObjectId("XXXXX"),
    "SearchKey" : "1234",
    "SearchTerms" : {
        "STA" : ["1"],
        "STB" : ["asdfasdf"],
        "STC" : ["another"]
    }
}

The SearchTerm elements are not fixed – sometimes we’ll have STA without STC, for example.

I can do this:

var map = function() {
    for (key in this.SearchTerms)
    {
        emit(key, 1);
    }
}

but I can’t do this:

var map = function() {
    for (var i=0; i< this.SearchTerms.length; i++)
    {
        emit(this.SearchTerms[i], 1)
    }
}

because the latter doesn’t produce any results after the reduce. Why not?

As an aside – what I need to do is count the cross-product of the search terms over all documents, that is, find the incidence of (STA and STB) and (STA and STC) and (STB and STC) in the case above. If someone knows how to do that right away, that works even better.

As always, thanks for the help

  • 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-29T11:13:20+00:00Added an answer on May 29, 2026 at 11:13 am

    The key that you emit should be a composite of both keys.

        var map = function() {
            if(!this.SearchTerms) return;
            for(var i = 0 ; i < this.SearchTerms.length; i++){
                var outerKey = this.SearchTerms[i];
                for(var j = i + 1; j < this.SearchTerms.length; j++){
                   var innerKey = this.SearchTerms[j];
                   // assuming you don't care about counting (STA and STC) separately from (STC and STA), 
                   // then order doesn't matter, lets make sure both occurences have the same key.
                   var compositeKey = (outerKey < innerKey) ? outerKey+"_"+innerKey : innerKey+"_"+outerKey; 
                   emit(compositeKey, 1);
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user document which has a group field. This field is an
I have an xml document which consists of a number of the following: -
I have an XML document which contains nodes like following:- <a class=custom>test</a> <a class=xyz></a>
I have an XML document which looks something like this: <meadinkent> <record> <comp_div>MENSWEAR</comp_div> <sty_ret_type>ACCESSORIES</sty_ret_type>
I have an versioned document store which I want to access through an dict
I have got an XML document which looks something like this. <Root> <Info>....</Info> <Info>....</Info>
I have created a xslt document which formats an xml document, but I would
I am using MSXML3 and have loaded an xml document which is a HTML
I have a document library in MOSS 2007 which has folders and files. Document
I have an Eclipse feature which includes several bundles. I want to tell p2

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.