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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:45:28+00:00 2026-05-23T17:45:28+00:00

Is there a way to return the newly created document’s _rev and _id field

  • 0

Is there a way to return the newly created document’s _rev and _id field to the client from an _update function?

  • 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-23T17:45:29+00:00Added an answer on May 23, 2026 at 5:45 pm

    You can, however the solution is not perfect.

    You already know the document _id in the update function. Either you are computing it yourself, or using user input, or if you wish to let CouchDB produce an ID automatically, then use the req.uuid value.

    function(doc, req) {
        // An example _update function.
        var id;
    
        id = "Whatever";   // Pick one yourself, or...
        id = req.query.id; // Let the user specify via ?id=whatever, or...
        id = req.body;     // Let the user specify via POST or PUT body, or...
        id = req.uuid;     // Use a random UUID from CouchDB
    
        var doc = {"_id":id, "other_stuff":"Whatever other data you have"};
        log("Document _id will be: " + doc._id);
        return([doc, {json: {"success":true, "doc":doc}]);
    }
    

    Unfortunately, you do not know the _rev in the show function. However, CouchDB will send it to the client in the HTTP header X-Couch-Update-NewRev.

    For example:

    HTTP/1.1 201 Created
    X-Couch-Update-NewRev: 1-967a00dff5e02add41819138abb3284d
    Server: CouchDB/1.1.0 (Erlang OTP/R14B03)
    Date: Tue, 12 Jul 2011 06:09:34 GMT
    Content-Type: application/json
    Content-Length: 14
    
    {"stuff":true}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to return an array from a function? More specifically, I've
Is there a preferred way to return multiple values from a C++ function? For
Is there a way to return a random row from a table using LINQToSQL?
Is there a way to return a point for a string within a text
Is there a way to return a new version of an array/hash that does
Instead of returning a common string, is there a way to return classic objects?
Is there an easy way to return data to web service clients in JSON
Is there a (simple) way to return the amount of elements colliding with a
I would like to know if there is any way to return an char
Hope this makes sense... Is there a simple way to return a set of

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.