You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/05/22 13:36:45 UTC

[GitHub] ondra-novak commented on issue #782: Using custom revision numbers when creating documents

ondra-novak commented on issue #782: Using custom revision numbers when creating documents
URL: https://github.com/apache/couchdb/issues/782#issuecomment-390992599
 
 
   Custom revisions works without any issue in CouchDB 2.1.1. You just need to specify new_edits=false and include correct _revisions field. It is simper than in looks and more logical than using the last revision field.
   
   PUT `http://localhost:5984/custom_revs/customRevTest?new_edits=false`
   
   ```
   {
   "_id":"customRevTest",
   "_revisions":{"start":1,"ids":["my_custom_revision"]},
   "foo":"bar"
   }
   ```
   The `_rev` field can be omitted if the document contains field `_revisions`. Because the revision of the document is always the first, so CouchDB can calculate it
   ```
   {
   "_id":"customRevTest",
   "_revisions":{"start":2,"ids":["my_super_extra_long_custom_revision","my_custom_revision"]},
   "foo":"bar2"
   }
   ```
   I have tested longer  revision than usual and passed
   ```
   {
   "_id":"customRevTest",
   "_revisions":{"start":3,"ids":["long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long","my_super_extra_long_custom_revision","my_custom_revision"]},
   "foo":"bar4"
   }
   ```
   Apparently you don't need to include the whole revision history. Once there is matching record, the CouchDB is happy.
   ```
   {
   "_id":"customRevTest",
   "_revisions":{"start":4,"ids":["short","long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long"]},
   "foo":"bar5"
   }
   ```
   The CouchDB is still tracking revision history.
   
   `GET http://localhost:5984/custom_revs/customRevTest?revs=true`
   ```
   {"_id":"customRevTest","_rev":"4-short","foo":"bar5","_revisions":{"start":4,"ids":["short","long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long","my_super_extra_long_custom_revision","my_custom_revision"]}}
   ```
   
   So you _can_ generate a custom revision. You can encode various information into it: For instance
   
   `N-<timestamp>_<userid>_<random>`
   
   you can easily track who made changes and when
   
   Has it some disadvantages? Yes. I still considering this technique as non-standard. It works, because it is part of the replication protocol. The database must accept any weird revisions as long as they are comprising correct history chain. From the database's perspective, the request looks as part of ongoing replication. 
   
   However, once the inconsistency is submitted, there is no 409 error. It results to creation of the conflicted document. 
   
   Also note that two different documents with the same `_rev` and `_id` are considered as equal.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services