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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:07:51+00:00 2026-06-07T23:07:51+00:00

I have an map function in a view in CouchDB that emits non-unique two

  • 0

I have an map function in a view in CouchDB that emits non-unique two array keys, for documents of type message, e.g.

2 array keys

The first position in the array key is a user_id, the second position represents whether or not the user has read the message.

This works nicely in that I can set include_docs=true and retrieve the actual documents. However, I’m retrieving duplicate documents in that case, as you can see above in the view results. I need to be able to write a view that can be queried to return unique messages that have been read by a given user. Additionally, I need to be able to efficiently paginate the resultset.

  1. notice in the image above that [66, true] is emitted twice for doc id 26a9a271de3aac494d37b17334aaf7f3. As far as I can tell, with the keys in my map function, I cannot reduce in such a way that unique documents will be returned.

  2. the next idea I had was to emit doc._id also in the map function and reduce with group_level=exact the result being:

    3 array keys

    now I am able to get unique document ids, but I cannot get the documents without doing a second query. And even in the case of a second query, it will require a lot of complexity to do pagination like this (at least I think so).

  3. the last idea I came up with is to emit the entire document rather than the doc._id in the third position in the array key, then I can access the entire document and likely paginate. This seems really brutish.

So my question is:

Is #3 above a terrible idea? Is there something I’m missing? Is there a better approach?

Thanks in advance.

  • 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-07T23:07:53+00:00Added an answer on June 7, 2026 at 11:07 pm

    See @WickedGrey’s comment to the question. The solution is to ensure that I never emit the same key twice for one document. I do this in the map function by keeping track of the keys as I emit them in an array, then skipping the emit if the key exists in the array.

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

Sidebar

Related Questions

I have a function that shows a map page so I can get the
I have a set of documents in CouchDB that are geolocalized - that is,
I have a function in jquery: $('#map').click(function(e) { var posX = $(this).offset().left, posY =
I have the following function: func addCatsToMap(m map[string][]CatHouse, meowId int, treats Set, dog *Dog)
I have a downloader function that downloads multiple files parallely. I use multiprocessing.Pool.map_async in
In my current setup, I have a typedef std::function<void (MyClass&, std::vector<std::string>) MyFunction; std::map<std::string, MyFunction>
I have a couchdb database containing different types of documents. Unfortunately some of those
I have the following query: view.reduce.group_level(5).keys which returns: [[1f9c79a33f399a7937d880c5f31e8dbc, 2011, 12, 29, 13], [1f9c79a33f399a7937d880c5f31e8dbc,
Ok guys, so I have a map view with annotations and when tapped, they
I have a CouchDB view from which I emit three or four fields. If

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.