-
download Couchbase Sync Gateway: http://www.couchbase.com/nosql-databases/downloads
-
move sync_gateway bin file to a directory that is included in your $PATH environment variable. For example: usr/local/bin
-
Prepare Sync Gateway Config:
{ "log": ["CRUD", "CRUD+", "HTTP", "HTTP+", "Access", "Cache", "Changes", "Changes+"], "interface":":4984", "adminInterface":":14985", "facebook":{ "register":true }, "databases":{ "gw":{ "server":"walrus:/Users/danil/Documents/temp", "bucket":"default", "sync": ` function(doc, oldDoc) { channel("all_docs"); if (doc.type === "salesperson") { var userID = doc.user_id; //if user logged as admin we add him access to all_docs channel and role if (doc.isAdmin) { access(userID, "all_docs") role(userID, "role:admin") } if (oldDoc) { //salespeople can only be approved by admin. when we approve sales person we grant him access to all_docs channel if(doc.approved && !oldDoc.approved){ access(userID, "all_docs") requireRole("admin") } else{ //salespeople can only be edited by themselves requireUser(userID) } } else{ //salespeople can only be created by themselves requireUser(userID) } } } ` } } }
-
Start sync_gateway with current config file:
sync_gateway syncgateway_walrus_config.json
-
Change
kSyncUrl
inConstants.h
tohttp://YOUR_IP:4984/gw
gw
- data base name specified insyncgateway_walrus_config.json
YOUR_IP
- you can find your ip by usingifconfig
command
-
Run application on your device and simulator
-
Turn on logging as admin to add modification in data base
-
See how data is synchronized between simulator and device
-
You can find how to setup your env with real server here: http://www.atkit.com/dev/couchbase-sync-gateway-setup-in-5-minutes-4-couchbase-lite/
Use these Commandline Arguments to see verbose logs of syncronization process:
-LogSync YES -LogSyncVerbose YES -LogRemoteRequest YES -Log YES
curl http://USERNAME:[email protected]:8083/DB_NAME/_changes
curl http://USERNAME:[email protected]:8083/DB_NAME/_user/
curl http://USERNAME:[email protected]:8083/DB_NAME/_user/USER_NAME {"name":"USERNAME","all_channels":["all_docs"],"email":"[email protected]","roles":["admin"]}
curl -v -XPUT http://USERNAME:[email protected]:8083/DB_NAME/_user/USER_NAME -d '{"all_channels":["all_docs"],"roles":["admin"]}'