Is it possible to sync in relational documents?

12 views
Skip to first unread message

parvez....@decurtis.com

unread,
Aug 6, 2017, 2:24:59 AM8/6/17
to Couchbase Mobile
For a document with below strucutre:
Doc A:
_id: "DOCA:<some uuid string>"
"firstName": "<data>"
"lastName": "<data>"
"email": "<data>"

Doc B:
_id: "DOCB:<some uuid string>"
docAID: "DOCA:<some uuid string>"
......other data for documentB

If we create a view on "DocB" to read it at client end (Couchbase lite ios) then will Couchbase lite sync document "DocA" as well? If no, then is there any provision to sync both documents as well due to the relationship so that when one query view for DocA then it is also able to access DocB. We do not want to embed DocA in DocB though it can be a good alternative.

Jens Alfke

unread,
Aug 7, 2017, 12:37:49 PM8/7/17
to mobile-c...@googlegroups.com
On Aug 5, 2017, at 11:24 PM, parvez....@decurtis.com wrote:

If we create a view on "DocB" to read it at client end (Couchbase lite ios) then will Couchbase lite sync document "DocA" as well?

There’s no connection between views and replication. They’re entirely independent subsystems that both access the database.

If no, then is there any provision to sync both documents as well due to the relationship so that when one query view for DocA then it is also able to access DocB. We do not want to embed DocA in DocB though it can be a good alternative.

The replicator will push or pull all* documents in the database by default.

Just be aware that the order in which docs are transmitted is undefined, so if you’re pulling from another database and both DocA and DocB are updated [or new], you may briefly see the update to DocB while DocA is still missing or out-of-date. This is a particular case of Eventual Consistency. So your app logic needs to be aware that related documents may temporarily be inconsistent with each other. If your logic requires consistency at all times, the only option is to put the data in a single document, which will always be updated atomically.

—Jens

* All docs you have access to, if you’re pulling from Sync Gateway.
Reply all
Reply to author
Forward
0 new messages