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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:57:12+00:00 2026-05-20T15:57:12+00:00

How to do sub selects in couchdb, or, how to match a superset key

  • 0

How to do sub selects in couchdb, or, how to match a superset key to a subset using group_level

I have a pretty complex question that hopefully has a not too complex answer to someone who’s not just learning map/reduce and couchdb for the first time.

I am working on a system that serves a json manifest to a client to configure itself with content that updates daily. On first run the clients register themselves with a few descriptive tags (say: screen size, OS, location), and the server returns back a group_id. The client uses that id to request its manifest every day. On the backend we arbitrarily group clients together that share certain tags to cut down on the number of unique manifests we need to store/serve.

Our sales/admin person has a webapp where he can setup audiences to target specific content at specific groups. An audience can overlap multiple groups. The trick is, when the client reports in to get a fresh manifest we need to figure out which audience is the best fit to that client’s group. The best matching audience will be the first audience who’s tags are a subset of the submitted groups tags, e.g.:

audience1: tagA, tagB, tagC, tagD
audience2: tagA, tagC

group1: tagA, tagB, tagC

This group should match audience2, not audience1.

If we were using an audiences tags to find the best group match (in other words, if group.tags were a subset of audience.tags) I could build a really effecient index like so:

[tagA, tagB, tagC], group1._id
[tagA, tagC, tagB], group1._id
[tagB, tagA, tagC], group1._id
[tagB, tagC, tagA], group1._id
[tagC, tagA, tagB], group1._id
[tagC, tagB, tagA], group1._id

and use group_level=2 with key=[tagA, tagC] to match audience2 against the second line in the index. The problem is, I can’t figure out how to do this going the other direction: matching a group.tags against an index of audience.tags, where the tags we know at query time (group.tags) are a superset of the tags we are trying to match against (audience.tags)

I’ve got a firm grasp on simple m/r views, but I keep hiting dead ends on this one. Every solution I come to involves doing some sort of sub select in my view function, which doesn’t work in couchdb views… any ideas on how I can attack a problem like this?

Hopefully this decription makes some sense.

  • 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-20T15:57:13+00:00Added an answer on May 20, 2026 at 3:57 pm

    The easiest solution I can think of is to:

    • sort the tags of each audience and emit the sorted array as the key of the view.
    • query the view using multiple keys, i.e. do a POST with {"keys": ["key1", "key2", ...]}.

    The keys are all the possible keys you are looking for, in reverse order of importance (rows are returned in the order of the keys specified.) Again, the tags in the keys are sorted.

    In your example the keys can be:

    [tagA, tagB, tagC]
    [tagB, tagC]
    [tagA, tagC]
    [tagA, tagB]
    [tagC]
    [tagB]
    [tagA]
    

    The first result is what you want, so you can use limit=1.

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

Sidebar

Related Questions

I have two IEnumerable collections that I would like to union. One selects news
How to move a sub directory from one directory to another, given that both
I have classX: Sub New(ByVal item_line_no As String, ByVal item_text As String) ' check
i have a sub with this signature Public Sub Save(ByVal obj As IPta) now
How do I copy a directory including sub directories excluding files or directories that
Let's say that I create a Sub (not a function) whose mission in life
I have a table with some data that looks like: id | type |
I wrote the following UPDATE command, but there's redundancy in the sub-selects. I'm not
I have a query with a complex concatenation in it. It's something along the
I have a query that needs to return results that are NOT matched in

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.