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 :(

Jay
  • 856
  • 7
  • 17
tamtoum1987
  • 1,957
  • 3
  • 27
  • 56
  • 2
    Where is your sync function? Without one you will never put any documents into channels – borrrden Feb 26 '19 at 05:04
  • 1
    ah it's for sure what i miss – tamtoum1987 Feb 26 '19 at 08: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' – tamtoum1987 Feb 26 '19 at 08:39

1 Answers1

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.

tamtoum1987
  • 1,957
  • 3
  • 27
  • 56
  • 2
    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. – borrrden Feb 27 '19 at 01:00
  • 1
    you right i just deleted sync on the user level and it still work – tamtoum1987 Feb 27 '19 at 09:04
  • @tamtoum1987 Would you consider correcting your answer and then accepting it so that others can gain from your experience? – G. Blake Meike Apr 17 '19 at 18:57