Revs are missing from view query docs


#1

Hi

Calls to access documents using design documents aren’t returning rev in their data

it used to be included inside [“value”]["_sync"]. _sync appears to have been removed from this data (I guess most of the data in here is only of internal relevance to sync gateway) and the online docs suggest that rev should now be inside each row in “rev”, but it isnt.

This is what I’m getting back from a call to

GET /{db}/{design-doc-id}/_view/{view-name}
{  
   "Collator":{  

   },
   "rows":[  
      {  
         "value":{  
            "channels":[  
               "domain_glowinthedark.co.uk"
            ],
            "name":"glowinthedark",
            "namespace":"glowinthedark.co.uk_flotsam_1",
            "domain_name":"glowinthedark.co.uk",
            "access":[  
               "glowinthedark.co.uk",
               "role:domain_glowinthedark.co.uk_member"
            ],
            "person_id":"person_glowinthedark.co.uk",
            "type":"domain"
         },
         "id":"domain_glowinthedark.co.uk",
         "key":"domain"
      }
   ],
   "total_rows":6
}

This really is a problem as without the revs for the documents they can not be updated.

Thanks

Paul


#2

That’s correct, the rev number isn’t included in the metadata returned as part of a result row. You can emit it in the value alongside the other properties you are already emitting however.

function(doc, meta) {
  var object = {};
  …
  var object.rev = doc.rev;
  emit("domain", object);
}

James


#3

Hi James,

Ok. But is the rev in the doc at this point? I am already doing

emit("domain", doc);

so it should already have the rev but it doesn’t. Is the rev instead in the meta? If so I could copy it across like this:

doc.rev = meta.rev;

emit("domain", doc);

#4

Hi James,

I looked in couchbase to see how the view functions are being wrapped.

It looks like meta is patched with both “rev” and “channels” from _sync and _sync is removed:

var sync = doc._sync;
…
delete doc._sync;
meta.rev = sync.rev;
meta.channels = channels;

P


#5

Looking at a document in the Couchbase Server bucket it looks like the revision number is stored as _rev (top-level field) and rev in the _sync dictionary.


Trying doc._rev doesn’t work?

James


#6

Hi James,

I don’t have _rev by default in my documents in couchbase, only if I write them in myself, but I’m only running 3.0.1 Community Edition, maybe this has changed since.

But I think I can pull it out from the meta if this is available to the view function

Using _rev in the docs is pleasingly old school can we have _id too?

P


#7

Hi James

I’ve just tested pulling the rev out from meta to my views like this:


function(doc, meta) {
    doc._rev = meta.rev;
    emit(doc.type, doc);
}

This works fine for CB 3.0.1 - I must update to 4 sometime soon.


#8

Hi @paulharter,

I thought the revision would be on the doc object (with doc._rev) but it doesn’t seem to be the case.
Glad it worked with meta.rev.

James