Reputation: 575
I'm using pouchDB for the first time, and as indicated in the docs I'm using put() so it will automatically handle revisions. However, when the code is running and there's an existing item with the same ID, it's still rejecting even when including a _rev.
Here's my code:
var db = new PouchDB('blog')
...
function saveCategory(category) {
var savedCategory = {
_id: 'category' + category.id,
_rev: '2-' + String(new Date().toISOString()),
name: category.name,
nicename: category.slug,
post_count: category.count,
description: category.description,
link: category.link,
parent: category.parent
}
return db.put(savedCategory).then((response) => {
$log.log(response)
}).catch((error) => {
$log.error('error saving category ',error)
})
}
Upvotes: 1
Views: 185
Reputation: 4362
This is not the purpose of the _rev
field. It is always generated by the server and not by your code. To update a document you must pull the entire document (including the _rev
field), update the desired fields, and then put the document. The value of _rev
should be the same as when you got it from the server.
If you have a new record, you do not need to set _rev
.
The pocketDB guide has a very useful section about this.
Upvotes: 1