How to exclude '_sync:rev' documents


#1

I’ve got some views on the sync_gateway bucket but they all contain documents with ids starting with “_sync:rev”. I assume these are internal sen-gateway docs and I should not be reading them?

What’s a suitable way to ensure they don’t appear in my views?


#2

@nick-couchbase

If you have created your views via the Sync Gateway RESP API, then the map function will contain the following line:

if (sync === undefined || meta.id.substring(0,6) == \"_sync:\") return;

This will return from the map function without further processing for all internal _sync: metadata documents.

If you are creating your views directly on CBS, then you can use a similar approach in your own views.

Here is an example of a complete view generated via the SG REST API (Note this is suitable for use via the Admin REST API only)

{
	"views":{
		"all_lists":{
			"map":"function(doc,meta) {
				var sync = doc._sync;
				if (sync === undefined || meta.id.substring(0,6) == \"_sync:\") return;
				if ((sync.flags \u0026 1) || sync.deleted) return;
				delete doc._sync;
				meta.rev = sync.rev;
					(
					function (doc, meta) { 
						if (doc.type != \"list\") { return; } 
						emit(doc.title, doc.owner); 
					}
					) 
					(doc, meta);
					doc._sync = sync;
			}"
		}
	}
}

#3

Perfect, thanks.

I’m not creating views via the sync gateway - as discussed elsewhere views in the sync-gateway aren’t supported feature due to performance concerns.