I have a view that will stop outputting results, and the only way I’ve been able to troubleshoot it is through trial and error. Is there a better approach to get logs and debug information for a view? I assume its running into JavaScript errors, and I keep trying to guard against them. Is there something equivalent to console.log from a View’s map function? If so, where can I see that output?
Below is the View in question, which gets published through the Sync Gateway, so it gets wrapped by another function.
function(doc,meta) {
var sync = doc._sync;
if (sync === undefined || meta.id.substring(0,6) == "_sync:")
return;
if ((sync.flags & 1) || sync.deleted)
return;
var channels = [];
var channelMap = sync.channels;
if (channelMap) {
for (var name in channelMap) {
removed = channelMap[name];
if (!removed)
channels.push(name);
}
}
delete doc._sync;
meta.rev = sync.rev;
meta.channels = channels;
var _emit = emit;
(function(){
var emit = function(key,value) {
_emit(key,[channels, value]);
};
(function (doc, meta) {//
try{
if (!doc.channels || doc._deleted) return;
doc.channels.forEach(function (channel) {
emit(channel, doc.DocumentType);
});
}
catch(exception){
//ideally we would log this, but Couchbase doesn't seem to provide a way to d that
}
}) (doc, meta);
}());
}
@jamiltz: If you define the view through Couchbase Server, then you have to check the _sync property to make sure the doc you’re mapping is a real document and not metadata like an attachment or user account.
@elevine: Call log("...") to log a message from a map function.
@jens I tried calling log from within my map function, but I see the following in the mapreduce_errors.log:
[mapreduce_errors:error,2015-07-21T12:54:49.777,ns_1@127.0.0.1:<0.23888.1631>:couch_set_view_updater:-do_maps/3-fun-0-:743]Bucket `sync_gateway`, main group `_design/dev_skylight`, error mapping document `_sync:local:c2e61b143b8797e48a5f5fe23d0ce29537e29d39` for view `getAllDocuments`: ReferenceError: log is not defined
We are using Couchbase 3.0.1 Community Edition. Is the log function not available for this version?
It’s unfortunately not available for 3.0.1. 4.0 Beta is the first that has this function*. That said, since you’re running into this at development time, you can probably use 4.0 to develop, then test/deploy on 3.x.
By the way, I answered you on Gitter as well. There I suggested:
the strategy I used before that @elevine was to put something at the very end of the btree and scan for that, so it was sort of like logging
I think I had [“ZZZDEBUG”] or probably something smarter as my key