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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:12:11+00:00 2026-06-02T15:12:11+00:00

Suppose I have couchdb docs that look like so: { _id: id, _rev: rev,

  • 0

Suppose I have couchdb docs that look like so:

{
    "_id": "id",
    "_rev": "rev",
    "title": "foobar",
    "URI": "http://www.foobar.com",
    "notes": "",
    "date": 1334177254774,
    "tags": [
        "tag1",
        "tag2",
        "tag3"
    ],
    "date_modified": 1334177278457,
    "deleted": false
}

What I want is to create an inverted index from the tags, so I end up with something like:

{
    "tag1": [
        _id,
        _id,
        _id
    ],
    "tag2": [
        _id,
        _id,
        ...
    ]
}

From what I’ve read and tried, couchdb might not let me do it. I can’t get it done in the map phase, and it doesn’t seem like I can do it in the couch reduce phase.
Is this something I need to accomplish in another layer of the app?

  • 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-02T15:12:14+00:00Added an answer on June 2, 2026 at 3:12 pm

    You can achieve this with the map feature of CouchDB.

    CouchDB likes tall lists, not fat lists. So, to “cut with the grain” on this problem, you want a view keyed on the tag, with one row per document ID.

    // View rows (conceptual diagram)
    // Key  , Value
    [ "tag1", "_id1"
    , "tag1", "_id2"
    , "tag1", "_id3"
    
    , "tag2", "_id2"
    , "tag2", "_id4"
    , "tag3", "_id6"
    ]
    

    To get a list of all document IDs with a tag, hit the view with a tag name as the key, GET /db/_design/ddoc/_view/tags?key="tag1".

    This should be enough. But as lagniappe, you can set the "reduce" value to "_count" to get a count of all tags used (useful for building a tag cloud). Just remember to add &reduce=false when you want to query your index.

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

Sidebar

Related Questions

Suppose I have a data frame, df, that looks like: f t1 t2 t3
Suppose I have an array that looks like this array ([apple] => 1, [dog]=>2,
Suppose I have an HTML page that looks something like this: <html><body> 00123 <input
Suppose I have a vertical menu that is coded like this: <ul class=sub-menu> <li
Suppose i have an XML file, that i use as local database, like this):
Suppose I have a pure virtual method in the base interface that returns to
Suppose I have a static method of my class that returns an object of
Suppose we have the name written in any none-latin letters - languages, like Arabic,
Suppose I have a class Baz that inherits from classes Foo and Bar ,
Suppose I have a process that is updating a record and encounters a record

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.