I've got android and web apps. Android app uses Couchbase Lite, web app uses Couchbase. I'm using Couchbase Sync Gateway to enable data replication between those two databases.
So far it works ok for sending data from mobile and receiving it both in web app and second mobile device. I noticed that all send documents have "_sync" parameter added.
My question is how can I enable documents added through web app (to couchbase database) to take part in replication? (they don't have field "_sync" by default)
edit
As Legendary_Hunter suggested I tried using Shadow, but still can't get it working. My config file:
{
"log":["CRUD+", "REST+", "Changes+", "Attach+"],
"databases": {
"kris_mobile_db": {
"server":"http://192.168.0.11:8091",
"sync":`
function (doc) {
channel (doc.channels);
}`,
"bucket":"kris_mobile_db",
"users": {
"GUEST": {
"disabled": false,
"admin_channels": ["*"]
}
},
"shadow": {
"server": "http://localhost:8091",
"bucket": "kris_mobile_db_sync"
}
}
}
}
edit2 (29.05.16)
public class DatabaseManager {
private static DatabaseManager manager;
private static CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder().autoreleaseAfter(6000).build();
private static String bucketName = "kris_mobile_db";
private Cluster cluster;
private Bucket bucket;
public static DatabaseManager getInstance(){
if(manager == null)
manager = new DatabaseManager();
return manager;
}
public Bucket getBucketInstance(){
if(bucket == null)
bucket = cluster.openBucket(bucketName);
return bucket;
}
public boolean establishConnection(String host, String port, String bucketName){
// host: 192.168.0.11, port: 8091
cluster = CouchbaseCluster.create(env, host+":"+port);
DatabaseManager.bucketName = bucketName;
bucket = cluster.openBucket(bucketName);
return true;
}
}
and inserting is like
JsonDocument doc = JsonDocument.create(docId, content);
DatabaseManager.getInstance().getBucketInstance().insert(doc);
edit3
So finally I managed to get shadowing working. If anyone had the same problem. My basic database is kris_mobile_db and syncGateway shadowing database is kris_mobile_db_sync. Config file:
{
"log":["CRUD+", "REST+", "Changes+", "Attach+"],
"databases": {
"kris_mobile_db": {
"server":"http://192.168.0.11:8091",
"sync":`
function (doc) {
channel (doc.channels);
}`,
"bucket":"kris_mobile_db_sync",
"users": {
"GUEST": {
"disabled": false,
"admin_channels": ["*"]
}
},
"shadow":{
"server":"http://192.168.0.11:8091",
"bucket":"kris_mobile_db"
}
}
}
}
Just use bucket shadowing. It is bidirectional syncing of sync gateway bucket with any bucket of couchbase server.