Couchbase Lite One way sync

Am planning ionic app with couchbase lite which using one way sync (Syngateway to local)…

Each document will have read status which is specific to single user so I don’t want that attribute to be replaced with on replication…

Do we have any way to do this?

One more quick question can we update only few attributes of a document.

You can update individual properties.

If you change a document on the device, the changes won’t be synced back to the server if the device doesn’t run a push replication. But the next time a change to the document is received from the server, it’ll be considered a conflict and you’ll have to merge it.

In your situation it would probably be better to treat the docs from the server as immutable, and have a second document on the device that records the read state of a doc.

Thank you. Great Solution… I need check workaround for using immutable document with rest.

@jens:

In your situation it would probably be better to treat the docs from the server as immutable, and have a second document on the device that records the read state of a doc.

is there any official way to do this…or do we need to depend on our own logic…
AS far as I know there is no relations in couchbase so I need to create copy of actual document and use for local modification… In this case I had situation how should I handle server changes.

To create a relation you just store the ID of the target document in a property in the source document. Then to follow the relation you just get that property value, and then get the doc with that ID from the Database.

@jens: You mean for each document looping… and as per you for this also I need to modify document to store targe ID which again creates conflicts right.

I don’t know what you mean by “for each document looping”.

I need to modify document to store targe ID which again creates conflicts right.

No, you put the relation in the document you create locally, referring to the immutable doc pulled from the server. There’s no need to modify the doc from the server. If you want to follow the relation backwards, create a view that indexes the link property.

I mean do I need to create manually local document with server doc relation or is there any official way to do automatically…
As I didn’t find any API documentation related to this asking this question.

I hope you know that I am using phonegap plugin which means communicate via RestAPI. Couchbase Capella for Mobile Developers

There is nothing that does this for you. You can implement it yourself pretty easily.

How to get relation document in couchbase… As per me map function is allowing to use doc,meta objects…
Each time if we want to get relation document in call back will be performance fact is what I am thinking.

I’m sorry, I don’t understand your question. Can you describe more specifically what you want to do?

As per our conversation I am creating local document with reference of server document…
Currently on couchbase:change event creating local document… in list view getting all local documents and with loop getting server document.

So my question is can I get related document using map function instead of getting with loop and query.

It just takes one database GET to fetch the remote doc for a local doc.

But if you want to do it automatically, in your map function on local docs emit a value that’s a dictionary/map with a key _id whose value is the document ID of the remote doc. That will tell the query to return the remote doc instead.

@jens
In map function how can I emit remote document? Is map function allow me to write query inside… if possible can you paste sample map function

My Current Map Function.
messages: {
map: function(doc) {
if (doc.type && doc.updatedOn && doc.title) {
var value = {
id: doc._id,
type: doc.type,
title: doc.title,
description: doc.description,
featuredImage: doc.featuredImage,
rev: doc._rev,
totalLike: doc.totalLikes,
totalShares: doc.totalShares,
authorName: doc.author.firstname + " " + doc.author.lastName,
updatedOn: doc.updatedOn,
read: doc.read, // This is the attribute which I don’t want to sync …
link: (doc.type == “link”) I ? doc.link : false
};
emit(doc.updatedOn, value)
}
}.toString()
},