Devidas
Devidas

Reputation: 2517

Can I avoid "_rev" from my couchDB entry because My document is not going to change

I am working on couchdb with nodejs where I have requirement where my document is added once and only once. I think there is no need of _rev tag in my Document. As _rev value is long string and my data is very small it adds a big overhead and finally big document size. I am aware it is very integral part of couchdb but in some typical cases it becomes redundant. NOTE I also know that couchDB uses Multi-Version Concurrency Control (MVCC).

  1. Is there a way to remove this from Document ?
  2. Am I missing out something of critical which may create issue later ?
  3. If not avoid it completely atleast can I reduce the value very small ?

My point here is in short :

can I have entry like

"_id": "001" "value":"12"

"_id": "002" "value":"23"

where there is no such value as "_rev": "1-8b0b70974c6dd43edf4e07f12a9655af"

Upvotes: 1

Views: 522

Answers (2)

rsp
rsp

Reputation: 111366

It is impossible to disable revisions in CouchDB. Revisions are the integral part of the database. If you are sure that you don't want them then you may want to use some other database but if you use Mongo then it will store revisions. But look at it this way: if you have a requirement that your documents never change then how are you going to guarantee that? A revisions seems like a perfect feature to make sure that your documents never change. Not only because you can read them but also because if you never use them then you will not be able do update any document for which a previous revision is needed for updates.

Upvotes: 1

Dominic Barnes
Dominic Barnes

Reputation: 28429

If you don't want the _rev property transmitted when downloading a document, you can always use a show function to transform your document's JSON to exclude this property:

function (doc, req) {
  delete(doc._rev)
  return { json: doc }
}

This does mean you have to use the show function API instead of fetching the document directly, but you can use this approach to apply other domain-specific optimizations.

Upvotes: 1

Related Questions