2

My platform is Couchbase Server on version: 4.6.1-3652 Enterprise Edition (build-3652).

I have seen that in every document there is the history with the list of revisions. In N1QL, does anyone know how to get all the different bodies of each revision back?

For example, in this document I came to revision 4:

{
    "id": 123,
    "_deleted": true,
    "_rev": "4-54gtrg",
    // ... body ...
}

I am interested in returning to the "3-dsada" revision, can it be done?

Matthew Groves
  • 25,181
  • 9
  • 71
  • 121
Κωλζαρ
  • 803
  • 1
  • 10
  • 22

1 Answers1

2

My answer applies to Couchbase Server, which I assume you're asking about. When using Couchbase Mobile, there might be a different answer.

Short answer: it can't be done.

Longer answer: (I might be wrong or oversimplying here), but in Couchbase, the old revisions are tombstoned (marked for deletion). When cleanup occurs, these old documents will be purged permanently. So, the old document might not be actually deleted for a period of time, but (by design) there is no way to access those old revisions: only the latest.

Matthew Groves
  • 25,181
  • 9
  • 71
  • 121
  • Ok, it's what I read on this post https://github.com/couchbase/sync_gateway/wiki/Rev-Tree-Storage-on-Couchbase-Server in particular "non-leaf ancestor revisions that are no longer needed are stored temporarily in separate Couchbase Server docs, and then eventually discarded after a configurable time window (default: 5 minutes)".But I have a doubt on this rev history field inside at every document. I suppose the documents have stored inside a different hide bucket, I don't know.I'm here for that. I really want to understand why they put the history inside a document without to reach their body. – Κωλζαρ Jul 04 '19 at 09:00
  • 1
    You're asking about Sync Gateway, part of Couchbase Mobile. So it might be different. But there are reasons the history might be stored other than client retrieval, mainly an append-only storage strategy. – Matthew Groves Jul 04 '19 at 12:43
  • can be deeper your answer? – Κωλζαρ Jul 04 '19 at 13:18
  • 1
    I'll give a short version, but check out the documentation for more details. Couchbase Server uses an append only strategy. When a document is updated, two things happen: a new revision is appended and the old revision is tombstoned (marked for later deletion). The tombstoned document hangs around for some period of time (for a variety of reasons), but it isn't meant for developers to access. – Matthew Groves Jul 08 '19 at 16:16