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

  • Home
  • SEARCH
  • 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 9045469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:20:01+00:00 2026-06-16T11:20:01+00:00

I’m using couchrest_model to interact with CouchDB from ruby. I have a bunch of

  • 0

I’m using couchrest_model to interact with CouchDB from ruby. I have a bunch of documents in a database, each of which I’ve added a key “updated_by” to, which I want to keep information about the user who made the changes that generated that revision.

Is this the right way to do things?

If this is the right way, how should I use couchrest_model so that I can make requests of user data as well as my main database?

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-16T11:20:03+00:00Added an answer on June 16, 2026 at 11:20 am

    The only way is to force updated_by field by equal userCtx.name value thought validate_doc_update function:

    function(newdoc, olddoc, userctx, secobj){
       if (newdoc.updated_by != userctx.name)
           throw({"forbidden": "`updated_by` field should match real updater user name"})
    }
    

    This function will control content for all documents (except design ones), requiring them to have data in the way you expected.

    You may stop at this point, but he has one flaw: all your clients will have to set this field manually. That’s awkward and not let them to “relax”. To solve this problem CouchDB provides update functions, that allows to setup some part of business logic on server side removing this knowledge from client realizations. So your update function may looks like:

    function(doc, req){
       if (!doc){ // new doc
         doc = JSON.parse(req.body);
       }
       doc.updated_by = req.userCtx.name;
       return [doc, {"json": {"status": "ok"}}
    }
    

    And he let you setup updated_by field in right way. More over, you may extend this function by adding more and more meta fields (e.g. userCtx.peer hold client IP address) and if your clients will use it they wouldn’t require any updates on you metadata changes.

    But note that you need to provide some exceptions for service users or you’ll get broken replications between CouchDB nodes since validate function will reject all documents which has different from user name updated_by value.

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have thousands of HTML files to process using Groovy/Java and I need to
Let's say I'm outputting a post title and in our database, it's Hello Y’all

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.