In my couchDB database I have a filter which only emits documents that have doc.my_key == "value" like so:
{
"id": "_design/test".
"filters": {
"value_only": "function(doc){return (doc['my_key'] == 'value');}"
}
}
When I write two documents like this:
{
"id": 1,
"my_key": "cheeky"
}
{
"id":2,
"my_key": "value"
}
Then the json at /this_database/_changes?filter=test/value_only reads:
{
"results":[
{"seq":2,"id":"2","changes":[{"rev":"1-463e18b34dfa529dd9b39981ad3293f4"}]},
],
"last_seq":4
}
This is cool. CouchDB is cool. However I now update document #2 like this:
{
"id":2,
"my_key": "no longer value"
}
The filtered changes feed is now empty. I know that this is because when a document is updated previous seq numbers for that document are removed from the changes feed, but are there any parameters I can pass/configuration edits I can make so that I am returned the most recently emitted revision of that document’s ID?
Suddenly, there is no such parameter for changes feed. The only way you may handle all changes events is to listen feed as continuous stream. However, even this case couldn’t give you any warranty that received revision number will be available due to race condition with compaction operation.
The changes feed emits only leafs revisions and the winning ones if there was any conflicts(e.g. document has two “heads” with different leaf revision). For latter ones you may pass
?style=all_docsquery argument to retrieve all existed leafs for document.For example:
The default behaviour (
style=main_only) will yield the winning revision:4-ijk, while withstyle=all_docsthe changes feed yields both3-123and4-ijkrevisions for this document.Not sure in, but I suppose that is optimized usage of database data structure and protection against conflicts with compaction which handles all non leafs revisions.