Document format and size restriction using sync function?

Is there a way to control the format and size of a particular type of the document on SG side (using sync function I assume) when it comes to document update and creation?


What do you mean format and size? You have JSON and attachments, so I’m wondering what you’re trying to achieve.

Sync Gateway doesn’t currently allow modifying documents in the sync function. You could disallow documents, but that’s about it. It’s common to validate docs in the sync function.

Thanks for the reply.

I am trying to control what user can write/update in a user profile type document. Would like to limit the possibility of the DB being misused/abused.

BTW, how to disable attachment?


BTW, I found the following and will try it out. I am still interested in how to disable attachment however.


Hi Felix,

By default, synctos blocks attachments on document types unless the document definition sets allowAttachments to true. This should address one of your concerns.

Sync Gateway (or rather, Couchbase Server) imposes a limit of 20MB per document or attachment, but if you’d like more control over attachments, the attachmentReference property validation type in synctos may be helpful. It allows you to specify the supported file extensions, content types and maximum size of a referenced attachment. There are some caveats that are explained in the project README though.

I’m the maintainer of the project, so let me know if you have any questions.

Thank so much. I was about to reply I found that in Synctos Github readme…

I got what I want now. Back to the readme… :smiley:

Great project btw.

FYI, I just published a new version of synctos (1.8.0) that provides far greater control over document attachments. You may find it useful.

You’ll find the details in the release announcement.

1 Like


Can you please tell me how did you able to use synctos ?
I have also generated sync function using synctos. But then whenever I update any document ,it says-

“error”: “Internal Server Error”,
“reason”: “Exception in JS sync function”

What changes can be done after generating sync function?