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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:07:56+00:00 2026-05-26T10:07:56+00:00

CouchDB docs seem to have a key attached; it does not show up when

  • 0

CouchDB docs seem to have a key attached; it does not show up when retrieving a single document but you can use them to retrieve ranges of documents such as :

 wget "http://localhost:5984/monitor20n/_all_docs?startkey=1111&endkey=2222

However, apparently that key is always the same as the document id, so that all you obtain is stuff like this

{"total_rows":14269,"offset":0,"rows":[
{"id":"128127896626798592","key":"128127896626798592","value":{"rev":"1-4e07e2c4b4eddfad5846ddf905337197"}},
{"id":"128128575021907970","key":"128128575021907970","value":{"rev":"1-43d983af1e837a4415b6167cae3b5de8"}},
... and so on }}

(see here key == id ). However, you can use more complex keys in views, including vectors which allow for much more complex interaction; at least, you can set the keys of views so you can now in advance what to search without looking up document ids.
The question is now: Can you set those keys up when creating a document? Or maybe after creating it?
An obvious workaround is to create a view like this

function (doc) {
    emit(doc.key,doc)
}

however, I would like to know if there’s a more direct way of obtaining the same effect.

  • 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-26T10:07:57+00:00Added an answer on May 26, 2026 at 10:07 am

    Keys are an important part of CouchDB views. With a view, the key does not have to be the document ID. But the only way to produce a key is to use the emit function from within a view. There is no property that you can set that will automatically become the key.

    Think of _all_docs like a built in view. To be consistent it follows the same output as a regular view, and it uses the id as the key. But you can’t change the _all_docs view. If you wanted to provide your own _id when you save a document, that will end up being the key.
    So if you wanted custom ‘keys’ in the ‘_all_docs’ view you could create docs like this:

    { _id: ‘Sample1’ }, {_id: ‘My2’}. and after they are saved, when you request the ‘_all_docs’ view you would get:
    {“total_rows”:2,”offset”:0,”rows”:[
    {“id”:”Sample1″,”key”:”Sample1″,”value”:{“rev”:”1-4e07e2c4b4eddfad5846ddf905337197″}},
    {“id”:”My2″,”key”:”My2″,”value”:{“rev”:”1-43d983af1e837a4415b6167cae3b5de8″}},
    … and so on }}

    Here is a link about what makes a documentID:

    http://wiki.apache.org/couchdb/HTTP_Document_API#Special_Fields

    While it does not say explicitly, you can’t use objects or arrays as DocumentIDs.

    Hope that helps.

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

Sidebar

Related Questions

How can I retrieve document from CouchDB based on its field, not by ID?
Using CouchDB , I currently have a document which represents an idea, you can
Since CouchDB does not have support for SQL alike AUTO_INCREMENT what would be your
Though I use CouchDB-specific JQuery verison, the problem can appear to be not related
CouchDB, version 0.10.0, using native erlang views. I have a simple document of the
I am already excited about document databases and especially about CouchDB's simplicity. But I
How can I get the fields for a couchdb document? I'm thinking of how
Can CouchDB's filtered replication be set to replicate not only the most recent version
Does CouchDB have an equivalent to expire like in Redis? Example for Redis expire:
Since CouchDB has very few API documentation (at least I can not find it),

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.