Can anyone tell me that how do we use channels in the sync function to give access?
I have certain channels in the document.
When I am trying to update something, error says;
{
“error”: “Forbidden”,
“reason”: “missing channel access”
}
Do anyone knows how to use synctos?
I have inserted the generated sync function into Sync_gateway.json.
But Can you please elaborate on this topic.
when document changed, you can route document to some channel,and assign channel to user by the property of the changed document.
FYI
https://developer.couchbase.com/documentation/mobile/1.4/guides/sync-gateway/sync-function-api-guide/index.html#example
Hi @atom_yang
I have generated the sync function using it but it’s not working.
Can you tell me how to create document type definition file for synctos.
What’s the format? May be I am wrong somewhere there.
I didn’t use synctos ,I think README is clear
FYI
Hi @atom_yang and @OldSneerJaw
I have already read and implemented as it says-
Have a look at my doc-definition file:
Document Name or type -DocumentType
DocumentID- _id
Channel-DocumentType
→
{
channels: function(doc, oldDoc) {
var DocumentType = getDocumentType(doc, oldDoc);
return {
view: toSyncChannel(id, ‘DocumentType’),
write: ‘DocumentType’
};
},
authorizedRoles: defaultAuthorizedRoles,
authorizedUsers: defaultAuthorizedUsers,
typeFilter: function(doc, oldDoc) {
return /^DocumentType.[A-Za-z0-9-]+$/.test(doc._id);
},
immutable: true,
propertyValidators: {
type: typeIdValidator,
_id: {
type: ‘string’,
required: true,
immutable: true
},
type: {
type: ‘string’,
required: true,
immutable: true
},
RegisteredDate :
{
type: ‘string’,
required: true,
immutable: true
},
IssueDate :
{
type: ‘string’,
required: true,
immutable: true
}
}
};
Sync function has been created using this js File and I inserted it in the sync_gateway.json but not getting implemented.
Whenever I update any document, it says:
{
“error”: “Internal Server Error”,
“reason”: “Exception in JS sync function”
}
Need Help in understanding.
Anyone can also help.
Hi @jens
Can you go through this problem and let me know where am I getting wrong in generating sync function?
using sync function might be easier. can you show your ACL requirements and routing requirements and document design?
Sorry, I don’t know anything about synctos.
Hi @atom_yang,
This is all what I have done-
Steps to create synctos sync function on ubuntu server:
apt-get install npm
mkdir /home/tanu
npm install synctos
doc-definition.js (File has to be created in the project directory)
apt-get install node
apt-get install nodejs-legacy
cd /home/tanu/node_modules/synctos
./make-sync-function /home/tanu/node_modules/synctos/doc-definition.js /home/tanu/node_modules/synctos/generated-sync-function.js
(Append the contents of generated file in the sync_gateway.json)
And you can see the doc-definition file above as shown.
And my document design is like this-
{
"RegisteredDate ": “2017-09-22T15:03:04Z”,
"IssueDate ": “2017-09-25”,
“_id”: “DocumentType::0002218D-C485-4C7B-8A6C-F7D10F880568”,
“_rev”: “42-f797cc6661c7b3f818f1171db0d46e11”,
“channels”: [
“DocumentType”,
],
“type”: “DocumentType”
}
I have validated each field in sync function but still not getting implemented.