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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:29:45+00:00 2026-06-01T22:29:45+00:00

I have the following method that stores or updates a list of event json

  • 0

I have the following method that stores or updates a list of event json objects. I couldn’t find a bulk create_or_update function for couchdb, I had to query each object and see if it exists in the database and create/update accordingly. Unfortunately this is highly inefficient, it takes 6 mins for 1725 events to be processed. Can someone propose a better design? It has to be done in a couple of seconds. My couchdb is actually a ssl cloudant database, and my app is hosted on Heroku, which is deferent than the app on heroku that is actually combined with cloudant.

def self.store(bulk, resource) 
            JSON::Validator.validate!(SCHEMA, bulk, :list => true)
            bulk.each{ |event|
                response = resource.get("/database-dev/_design/Event/_view/byEID?key=\"#{event['eid']}\"")
                if (response["rows"].nil? || response["rows"].empty?) then
                    o =  [('a'..'z'),('A'..'Z'),(0..9)].map{|i| i.to_a}.flatten  
                    o.push('-','_')
                    event['_id']  =  (0..50).map{ o[rand(o.length)]  }.join
                    event['resource'] = 'Event'
                    resource.post('/database-dev', event.to_json)
                else
                    resource.put("/database-dev/#{response['rows'][0]['id']}", event.to_json)   
                end
            }
        end 
  • 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-01T22:29:48+00:00Added an answer on June 1, 2026 at 10:29 pm

    You can use the CouchDB bulk document API to create-or-update. Of course, since you are “flying blind” with the _rev values, the trade-off is that you might create revision conflicts. That might not be a problem for you, or in some cases it may be impossible or extremely rare (depending on your application). Simply add the "all_or_nothing":true option in your POST body.

    Alternatively, you can do a bulk create-or-update in two round-trips. First fetch all the documents revisions, then post a traditional _bulk_docs request with all the _rev values set.

    POST /database-dev/_all_docs
    Content-Type: application/json
    
    {"keys": ["id_1", "id_2", "bad_id"]}
    
    HTTP/1.1 200 OK
    ...couch headers...
    
    {"total_rows":10,"offset":0,"rows":[
      {"id":"id_1","key":"id_1","value":{"rev":"1-6919deb28bdb1d4cf5b53188be5683be"}},
      {"id":"id_2","key":"id_2","value":{"rev":"1-37bb8117bc6c7b182ca26aae16717408"}},
      {"key":"bad_id", "error":"not_found"}
    ]}
    

    (You can do the same thing when requesting a view.)

    Now you know all the values for _rev to send in the _bulk_docs. (If it had a "rev" value, use that, otherwise, leave _rev out to create a new document.)

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

Sidebar

Related Questions

I have the following method that returns void and I need to use it
I have the following method that is replacing a pound sign from the file
I have the following method that is supposed to be a generic Save to
I have the following static method that prints the data imported from a 40.000
I have a method that contains the following (Java) code: doSomeThings(); doSomeOtherThings(); doSomeThings() creates
I have a method that I will use in the following contexts: 1. User
I have a program that makes use of the following method to get a
I have an interface (called Subject ) that has the following method: public void
I have a simple mapview that has the following viewdidload method and didupdate to
I'm looking for a data structure that has the following properties. Stores a list

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.