Print doc contents in Sync Function exception

Is there a way to print the contents of doc in the Sync Function? I have tried toString(), toMap() and toPlainMap() like this:

throw ({ forbidden: "New document is missing id property, id is " + doc.id + " and doc is " + doc.toString() });

but all of these are not working. I somehow want do debug what data doc contains as I assume that some data I expect to be there is missing.

You should be able to use JSON.stringify(doc) to get a string representation of the full doc.

You can also pair this with console.log() if you want it printed to the Sync Gateway logs.