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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:17:04+00:00 2026-06-06T15:17:04+00:00

I have some documents in couchdb that have fields that are arrays of id’s

  • 0

I have some documents in couchdb that have fields that are arrays of id’s for different associated documents:

{
  associatedAssets: ["4c67f6241f4a0efb7dc2abc24a004dfe",  "270fd4508a1222a1e2a27cbe7f002d9z"]
}

I would like to write a view that will let me pass in a key that is itself an array of ids, and then return documents whose associatedAssets fields contain one or more of the ids passed in via the key array e.g.

$.ajax({
  url: "/db/_design/design_doc/_view/summaryByAssociatedAssets",
  type: "post",
  data: JSON.stringify({keys: ["4c67f6241f4a0efb7dc2abc24a004dfe", "6c67f6241f4a0efb7dc2abc24a004dfd"]}),
  dataType: "json",
    contentType: "application/json",
})
.done(function(resp){
  console.log(resp[0]);
});

would return documents whose associatedAssets array contains one or more of the keys “4c67f6241f4a0efb7dc2abc24a004dfe”, “6c67f6241f4a0efb7dc2abc24a004dfd”.

I can’t access the keys in my view, so I’m not sure if I can do this? Is there a better way to accomplish this?

Thanks!

  • 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-06T15:17:07+00:00Added an answer on June 6, 2026 at 3:17 pm

    Your view just needs to generate an output row per associatedAssets element, something like this:

    function(doc) {
      if( doc.associatedAssets ) {
        for( var i=0, l=doc.associatedAssets.length; i<l; i++) {
          emit( doc.associatedAssets[i], doc );
        }
      }
    }
    

    Then you’d need to adjust your call so it ends up passing that keys array as a query string parameter, which will return only the rows from the view that match keys in that array.

    A total aside – assuming a recent CouchDB version, the best practices would be to replace doc in your emit with { _id: doc._id } and then use include_docs=true in your query so your view index doesn’t get filled up (unnecessarily) with full documents.

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

Sidebar

Related Questions

I have created a repeat control that list some documents. I would like to
Given that I have some number of documents in my CouchDB database, I would
I have a couchdb database containing different types of documents. Unfortunately some of those
Basic problem I have some large, but logically organised documents - and would like
We have some embedded documents that look like this: { _id : ObjectId(4e402353bc9f6ec5a6000001), first_name
I have some documents in CouchDB that contains a value called expire. e.g.: expire:
I have some code that iterates through 'Documents' in couchDB for docid in db:
I have some table DOCUMENTS that have a column TYPE_ID and a table named
I have a CouchDB update handler and would like it to return a response
I'm trying to aggregate some data I have in CouchDB. There are photo documents

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.