0

I am new to CouchDB / PouchDB and until now I somehow could manage the start of it all. I am using the couchdb-python library to send initial values to my CouchDB before I start the development of the actual application. Here I have one database with templates of the data I want to include and the actual database of all the data I will use in the application.

couch = couchdb.Server()
templates = couch['templates']
couch.delete('data')
data = couch.create('data')

In Python I have a loop in which I send one value after another to CouchDB:

value = templates['Template01']
value.update({ '_id' : 'Some ID' })
value.update({'Other Attribute': 'Some Value'})
...
data.save(value)

It was working fine the whole time, I needed to run this several times as my data had to be adjusted. After I was satisfied with the results I started to create my application in Javascript. Now I synced PouchDB with the data database and it was also working. However, I found out that I needed to change something in the Python code, so I ran the first python script again, but now I get this error:

couchdb.http.ResourceConflict: (u'conflict', u'Document update conflict.')

I tried to destroy() the pouchDB database data and delete the CouchDB database as well. But I still get this error at this part of the code:

data.save(value)

What I also don't understand is, that a few values are actually passed to the database before this error comes. So some values are saved() into the db. I read it has something to do with the _rev values of the documents, but I cannot get an answer. Hope someone can help here.

  • If you want to update a document, you need to pass it's last _rev otherwise it creates a conflict. For conflict resolution, take a look at [this](http://guide.couchdb.org/draft/conflicts.html) – Alexis Côté Oct 13 '16 at 14:09
  • @Alexis My understanding of "update" is that adjust parameters in an existing document. But I am deleting it and create it new. That's why I don't get it really as I thought I would delete everything from the database and the database itself... – TotoSchillaci Oct 13 '16 at 14:23
  • **data** stands for database? Also, what it the kind of "sync" that you are using between Couch and Pouch? – Alexis Côté Oct 13 '16 at 19:57
  • yes. It is the database of my main data. And I am using the sync as explained in the guide of PouchDB: `function sync() { syncDom.setAttribute('data-sync-state', 'syncing'); var opts = {live: true}; data.replicate.to(remoteCouch, opts, syncError); data.replicate.from(remoteCouch, opts, syncError); };` I found out that it is because I am using always the same ID when I create the document again. When I use datetime as ID the problem doesn't occur anymore, because the ID is always different – TotoSchillaci Oct 13 '16 at 20:06

0 Answers0