Replicator with custom collection and scope errors and keeps referring to unwanted _default collection

Hi,

I have set up the the sync gateway there is no default collection or scope for the sync gateway database only the dev scope and custom collections. Direct api call work fine, PouchDB can be made to work albeit using a proxy technique and per collection listeners.

I want to get Couchbase Lite to work. I am forking the community example for ReactNative but I will be modifying DatabaseMananger.java it to accept scopes and collections. The issue is even after I add the custom collection it keep referring to the _default collection

The version of the sync_gateway is
CouchbaseLite/3.1.6-2
Couchbase Sync Gateway/3.1.1 CE

So both of these support custom scopes and collections

I was able to connect to a different sync database with a default collection but I don’t want to do that.

This is the log

 ReplicatorID 3bb76eb6b04407d84474afd80bcf5de6
 LOG  Replicator Listener Response Replicator listener already exists
 LOG  replicator started Success
 LOG  Replicator Event : {"completed": 0, "status": "connecting", "total": 0}
 LOG  Replicator Event : {"completed": 0, "status": "connecting", "total": 0}
 LOG  Replicator Event : {"completed": 0, "status": "connecting", "total": 0}
 LOG  Replicator Event : {"completed": 0, "status": "busy", "total": 0}
 LOG  Replicator Event : {"completed": 0, "status": "busy", "total": 0}
 LOG  Replicator Event : {"completed": 0, "status": "busy", "total": 0}
 LOG  User is not authorized to sync with remote server. Check credentials and try again.
 LOG  Replicator Event : {"completed": 0, "error": "Collection '_default' is not found on the remote server
   (CouchbaseLite Android v3.1.6-2@33 (EE/release, Commit/85eee67315@eb3d346290fb Core/3.1.6 (6) at 2024-02-28T22:56:19.938904494Z) on Java; Android 10; SM-G960F)", "errorCode": 10404, "status": "stopped", "total": 0}
 LOG  User is not authorized to sync with remote server. Check credentials and try again.
 LOG  Replicator Event : {"completed": 0, "error": "Collection '_default' is not found on the remote server
   (CouchbaseLite Android v3.1.6-2@33 (EE/release, Commit/85eee67315@eb3d346290fb Core/3.1.6 (6) at 2024-02-28T22:56:19.938904494Z) on Java; Android 10; SM-G960F)", "errorCode": 10404, "status": "stopped", "total": 0}
 LOG  User is not authorized to sync with remote server. Check credentials and try again.
 LOG  Replicator Event : {"completed": 0, "error": "Collection '_default' is not found on the remote server
   (CouchbaseLite Android v3.1.6-2@33 (EE/release, Commit/85eee67315@eb3d346290fb Core/3.1.6 (6) at 2024-02-28T22:56:19.938904494Z) on Java; Android 10; SM-G960F)", "errorCode": 10404, "status": "stopped", "total": 0}

This is captured netwrok traffic

GET /atender-d/_blipsync HTTP/1.1
Host: [bla]:4984
User-Agent: CouchbaseLite/3.1.6-2 (Java; Android 10; SM-G960F) EE/release, Commit/85eee67315@eb3d346290fb Core/3.1.6 (6)
Sec-WebSocket-Protocol: BLIP_3+CBMobile_3,BLIP_3+CBMobile_2
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: qo3IIAPq6p6YWYYlFC5P5Q==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: permessage-deflate
Authorization: Basic [bla]
Accept-Encoding: gzip


HTTP/1.1 101 Switching Protocols
Connection: Upgrade
Sec-Websocket-Accept: KJW+L2lrY+iBUdPXZZ8IEPms9Vo=
Sec-Websocket-Protocol: BLIP_3+CBMobile_3
Server: Couchbase Sync Gateway/3.1.1 CE
Upgrade: websocket

�4 �(��� Content-Type�application/json�[{},null]��Ÿ

I’m essentially doing this in getReplicatorConfig (albeit parsing a config)

com.couchbase.lite.Collection currentCollection = database.createCollection("member-info", "dev");
config.addCollection(currentCollection, null);

The weird thing is in ~sync_gateway/logs/sg_info.log

2024-04-26T13:15:15.325+01:00 [INF] HTTP: c:#018 db:atender-d GET /atender-d/_blipsync (as <ud>test1@test.com</ud>)
2024-04-26T13:15:15.325+01:00 [INF] HTTP+: c:[4c043212] #018:     --> 101 [4c043212] Upgraded to WebSocket protocol BLIP_3+ (as <ud>test1@test.com</ud>)  (0.0 ms)
2024-04-26T13:15:15.325+01:00 [INF] WS: c:#018 db:atender-d Start BLIP/Websocket handler
2024-04-26T13:15:15.336+01:00 [INF] SyncMsg: #1: Type:getCollections Collections: [dev.member-info _default], CheckpointIds: [cp-YrJpZ/wmssH/k1Tfu2WQzkiLkdkVRe2oznTV+1/tV04= cp-V/HrjqSGWqu8P3Mr008KeDNgqhs=]
2024-04-26T13:15:15.394+01:00 [INF] HTTP: c:[4c043212] #018:    --> BLIP+WebSocket connection closed

Why is it [dev.member-info _default]? it should be just [dev.member-info] right?

If tried database.deleteCollection and/or config.removeCollection to try an remove the default collection but these produce null reference errors. I don’t want to get into a cargo cult situation, I can’t figure out where I’m goign wrong.

default collection is mutually exclusive to custom collections and scopes for the sync gateway according to your documentation you would need a different database per scope as far as I understand but could target the same bucket in Couchbase server. I’m only trying to replicate one scope and various collections in the one sync database that doesn’t have a default collection for obvious reasons.

Your documentation also implies that scope and collections in Couchbase Lite need to match on sync server. Am I missing anything?

The credential are correct and verified through the other approaches.

Thank you in advance.

Are you using the deprecated constructor for ReplicatorConfigurator which takes a database as an argument? For backwards compatibility this implicitly adds the default collection so that existing code doesn’t break just from upgrading. Use one of the others in that case. I’ll see if we can get a doc comment note about that.

config = new ReplicatorConfiguration(database, new URLEndpoint(url));

Is part or the RN community example code

I’m already working on a fork, so will look into the other constructor.

it could also be an order issue?

I only see two options here
https://docs.couchbase.com/mobile/2.1/couchbase-lite-java/db001/com/couchbase/lite/ReplicatorConfiguration.html

isn’t one for cloning?

Well, you are looking at the docs for version 2.1 which was released in August 2018, long before scopes and collections were even an idea. Notice the difference with a version that is up to date

Ah great now I see. yes google landed on it first should have targeted the correct version.

For general information those that wish use the newer constructor of the ReplicatorConfiguration some methods won’t be valid, which is more than just depreciated.

If you want to get the channels or documentIDs from ReplicatorConfiguration then you use getCollections() if you want to loop through the collections set using getCollectionConfiguration of the ReplicatorConfiguration passing the collection, with the CollectionConfiguration you can then use methods such as getChannels() or getDocumentIDs()

What I did notice is an error in the documentation

Use Collection.getDatabase

Collection doesn’t actually have that method

Chances are you already have the Database object and you can inject it where you want.

Small note that 3.2 will add in the getDatabase method but indeed for 3.1.x the docs appear to be incorrect.

1 Like