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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:00:19+00:00 2026-05-20T02:00:19+00:00

I think what I am trying to do here may be impossible, but this

  • 0

I think what I am trying to do here may be impossible, but this is worth a shot.

I have two doc types, Operator and Event.

In the example below, I am emitting 3 keys.

[place_id, operator_id, zone_name]

operator_id and zone_name are the common fields in both documents. So that is how I want to do the join between the two document types.

What I want to get back is the place_id as the first key from the first emit(), and the Event doc._id from the second emit().

That way, I can specific the startkey as the place_id I want to get back a list of Event._ids for.

function(doc) {
 if(doc.doc_type == 'Operator') {
 for(var i in doc.zones) {
   for(var ii in doc.zones[i].origs) {
     if(doc.zones[i].origs[i])
       emit([doc.zones[i].origs[i], doc._id, doc.zones[i].name], null);
   }
 }
} else if (doc.doc_type == 'Event') {
 for(var i in doc.rates) {
   if(doc.rates[i].zone) {
     emit([0, doc.operator_id, doc.rates[i].zone], doc._id);
   }
 }
}
}

The problem is the join wont work with that first value of 0 in the second emit();

I have tried emiting the keys [operator_id, zone_name] which allows the join to work, but the reduce() function takes to long and throws an error since the list of Event._ids grows to long.

I probably will have to break this up into two separate queries but hope to learn a different approach that I am missing.

  • 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-20T02:00:19+00:00Added an answer on May 20, 2026 at 2:00 am

    Everything from emit() is sorted by the key. Often, keys are arrays to get a nice sort order: the first element has highest priority, followed by the second element, etc. However even if the key is an array, it is still one thing and the whole view is sorted by that key.

    Therefore, to join between different documents, they have to sort adjacent to each other in the view. That means they should share their leftmost elements of the emit() key.

    P.S. It is probably not helpful to talk about “JOIN”s with CouchDB, although people sometimes do use the word.

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

Sidebar

Related Questions

I'm trying to get this simple PowerShell script working, but I think something is
I'm trying to think of clever, clear, and simple ways to write code that
I'm trying to think of a naming convention that accurately conveys what's going on
I've got a lot of pages in my site, I'm trying to think of
I'm trying to code what I think is a fairly routine AJAX pattern using
I'm trying to do what I think is a simple thing under Linux. I
I think I should mention I'm trying to get Entity Framework\SQL server to do
I'm trying to track down a memory leak and I think it has to
I'm trying to design a database for a sports meeting. I think I've got
I'm still working on groking the F# thing - trying to work out how

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.