1

I am trying to update bulk documents using nano couch package from npm (https://www.npmjs.com/package/nano) but sometimes due to different _rev for same document , couch is skipping the update for those documents . But in my case i want to update all the documents irrespective of _rev value

So i tried using new_edits: false which will ignore _rev value and force update all the docs , but in my case couch is skipping all the docs if i use new_edits: false it is not even updating single doc when i use that flag

below is my code snippet

await db.bulk({ docs: conf['docs'] , new_edits: false }).then(body => {
numberOfUpdates = body;
});

Is there any other way to update documents irrespective of _rev value using nano couch package

Glynn Bird
  • 5,507
  • 2
  • 12
  • 21
  • Does this answer your question? [Bulk updating a CouchDB database without a \_rev value per document?](https://stackoverflow.com/questions/6983930/bulk-updating-a-couchdb-database-without-a-rev-value-per-document) – smathy Jul 22 '22 at 02:07
  • No @smathy , actually both were similar questions but in the link you kept , they were using `curl` request to perform couchDB operations but in my case i am using couchDb's nano package in nodejs , so if even if i am using "new_edits" flag in this nano query it is not working – Praneeth Mandalemula Jul 25 '22 at 05:28
  • 1
    I think you're missing the main point there, read the accepted answer closely. – smathy Jul 25 '22 at 21:15

1 Answers1

0

Just Before making bulk save documents in couchdb, you need to:

  1. Fetch all the documents with _ids that you need to bulk save.
  2. Replace _rev from documents fetched from the db in #1 to the documents that you want to save in the db
  3. Now make bulk save call to the db

The above steps will ensure that when you make a bulk save call, you are passing the latest _rev which will avoid the Document Update Conflict(s).

Manish Kapoor
  • 488
  • 3
  • 16