0

I am using the latest Couchbase Server with Sync Gateway. On the client application swift I push a document like this:

 let userChannel = "\(self.login)" config.channels = [userChannel, "zzzz", "nurse1"] config.replicatorType = .pushAndPull _pushPullRepl = Replicator.init(config: config) _pushPullRepl?.start() 

On the server, I receive this document but the problem is that

 "channels": [ null ] 

So when I try to pull document by channel I receive 0 document.

I have a configuration file here:

 { "log": ["*"], "adminInterface": ":4985", "databases": { "dev": { "num_index_replicas": 0, "server":"http://localhost:8091", "bucket": "dev", "username": "admin", "password": "adminadmin", "users": { "admin": { "disabled": false, "password": "adminadmin"}, "nurse2": { "disabled": false, "password": "adminadmin", "admin_channels": ["nurse2", "_nurse2","nurse1", "_nurse1"]}, "nurse1": { "disabled": false, "password": "adminadmin", "admin_channels": ["nurse1", "_nurse1", "nurse2", "_nurse2"] } } } } 

}

Thank's for your responses.

Edit:

Sync function is

 "sync": `function(doc) {channel(doc.channels);}` } 

and i'm getting error

2019-02-25 18:07:14.234729+0100 CouchbaseLiteTest[2474:1149779] CouchbaseLite Sync ERROR: {Push#1} Got error response to rev -YFzAmAK0VWolQcrIv2DiWH 1-a82becb9eacf1c02d0514aeb7f97cfcef9816bda (seq #4): HTTP 500 'Exception in JS sync function'

i don't have error anymore but channel still null on server :(

3
  • 2
    Where is your sync function? Without one you will never put any documents into channels Commented Feb 26, 2019 at 5:04
  • 1
    ah it's for sure what i miss Commented Feb 26, 2019 at 8:37
  • 1
    i just add "sync": "function(doc) {channel(doc.channels);" and i'm getting error 2019-02-25 18:07:14.234729+0100 CouchbaseLiteTest[2474:1149779] CouchbaseLite Sync ERROR: {Push#1} Got error response to rev -YFzAmAK0VWolQcrIv2DiWH 1-a82becb9eacf1c02d0514aeb7f97cfcef9816bda (seq #4): HTTP 500 'Exception in JS sync function' Commented Feb 26, 2019 at 8:39

1 Answer 1

2

I found the solution i was connecting with nurse1 and nurse2 so i have to add function(doc) {channel(doc.channels);} to this users like this

 "users": { "admin": { "disabled": false, "password": "adminadmin"}, "nurse2": { "disabled": false, "password": "adminadmin","sync": `function(doc) {channel(doc.channels);}`, "admin_channels": ["nurse2", "_nurse2","nurse1", "_nurse1"]}, "nurse1": { "disabled": false, "password": "adminadmin","sync": `function(doc) {channel(doc.channels);}`, "admin_channels": ["nurse1", "_nurse1", "nurse2", "_nurse2"] } } 

Also i had to add channel to document before save it like this

 let channels = MutableArrayObject() channels.addString("nurse1") mutableDoc.setArray(channels, forKey: "channels") 

_________EDIT

sync function on the user level not necessary.

Sign up to request clarification or add additional context in comments.

3 Comments

This is not good. That is not the proper place for a sync function. It should be at the database level, not the user level. The reason it works is because this is the default sync function that you have used and so after you added the channels on the client side it will work but that is not related to the sync function you have put in there. It will throw an error in a future version.
you right i just deleted sync on the user level and it still work
@tamtoum1987 Would you consider correcting your answer and then accepting it so that others can gain from your experience?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.