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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:16:35+00:00 2026-05-25T00:16:35+00:00

I want to write a background program that will monitor the _changes feed of

  • 0

I want to write a background program that will monitor the _changes feed of a CouchDB, and possibly update the document. The problem is that the update causes another _change, and I get an endless loop! What’s the best way to avoid this?

For example, here is the specific scenario: I have a CouchApp where users modify documents through their browser. I also have a python program that creates a PDF version of a document and then attaches it as an attached file to the document itself. My problem is that doing the PUT Attachment to upload the PDF also triggers a document change. I have to be able to tell whether a change is being caused by the PDF upload, or not. It seems like it should be easy, but I can’t think of a simple way to do it. I would rather keep the PDF generator program be “stateless”, keeping any required state in the db itself.

Now, this can easily be done if I require that users who change the document set some sort of flag on the document to indicate that it needs to be processed. The trick is how to do it without requiring that.


I have come to the conclusion that a “_changes” listener should never modify the document that it listens to. In my case I decided to attach my PDF file to a separate document, in a separate “database” within couchdb, but using the same “_id” to make it easy to correlate. That way I don’t trigger a “_change” on the same documents that I am listening to. I could not get past the need to require every client that changes the document to somehow “flag” it as requiring processing ( by deleting the existing attachment, or otherwise setting some “dirty” flag ). After much pondering, I think that this will be a rule-of-thumb for me : that you must not modify a document upon receiving a “_change” notification for that document. Has anyone else reached the same conclusion?

  • 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-25T00:16:35+00:00Added an answer on May 25, 2026 at 12:16 am

    Use a filter function and and filter out the second change – either by the document structure change or by setting an additional flag to the changed document:

    function(doc, req)
    {
      if(!doc.hasStructuralChange) { //fix this
        return true;
      }
      return false;
    }
    

    or

    function(doc, req)
    {
      if(!doc.changed) { //set doc.changed during first update
        return true;
      }
      return false;
    }
    

    Edit: You can check for an attachment via if (doc._attachments)

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

Sidebar

Related Questions

I want write a program that when installed, runs in background and adds a
Problem: I want to write a process that will allow a user to take
I want to write a Ruby program that will always be running in the
I want to write a program that uses the GPL-licensed pandoc for Markdown processing.
I want to write a small program that given a time (in minutes) as
I want to write a program that responds when I press a certain key
Some background: I have an database that I want to use linq-to-sql to update
I have written a application which runs in the background. I want to write
I want to write a series of delegates that call one another. It's a
I want to write a command that specifies the word under the cursor in

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.