How to generate _id on conflict during replication of cloudant databases? - cloudant

While using the replication API https://docs.cloudant.com/replication_guide.html how to instruct cloudant to generate a new _id when there is a conflict?
Basically I have to merge documents from one database to another one ... I will specify "doc_ids" to replicate ... But if there is a conflict I want cloudant to generate a new _id and proceed on. Is this possible?

Cloudant, as with CouchDB, doesn't have any means to handle conflicts on your behalf. What this means is you'll need to handle this in your application code, which you can do my listening to the changes feed. If you are new to conflicts and conflict resolution you can use these guides.
https://cloudant.com/blog/introduction-to-document-conflicts-part-one/
https://cloudant.com/blog/introduction-to-document-conflicts-part-two/
https://cloudant.com/blog/introduction-to-document-conflicts-part-three/

Related

How to use shard key in update queries generated by SimpleMongoRepository

We are using Spring Data MongoDB to connect to an Azure CosmosDB instance that is sharded. We currently face the issue, that the default SimpleMongoRepository implementation does not seem to support specifying a shard key that is then used in the query section of the update command sent to the MongoDB (or CosmosDB in our case). Compared to MongoDB, CosmosDB require the shard key in every query hitting a sharded collection. MongoDB only suggests to specify it.
Anyway, we have not yet found a way to manipulate the save operation so that is uses the shard key in the query section of the update command as well. Implementing a custom repository seems to be tricky since most classes we require to implement that are private or package private.
Does anyone have experience with this or is in a similar situation?

How to handle deleting databases in Couch across multiple clients?

Within CouchDB it's sometimes the case that eventually you'll probably have more deleted documents within a database than active documents. After a while this becomes somewhat nonoptimal, as you're syncing more deleted document data than anything else.
The official documentation recommends periodically destroying the databases in order to get around this, but I've noticed that all that happens when doing this is that a client with a local copy of the database (e.g. if you have a database named "username" that's designed to replicate to a client device via Pouch), when it sees the blank database, refills it back up, deleted document records and all.
Short of changing the database name every time, is there any way to signal to other Couch instances that they shouldn't repopulate the new fresh and clean database, and instead take it as a new database entirely? Or, in fact, any other solution at all?
Yes, if you have bidirectional replication then the "other side" will replicate all the deleted docs back to the new DB. The only two options I can think of are to have a new database (with a new name, which is what the docs you linked to probably meant), or to use filtered replication so the client doesn't push up deleted docs (or doesn't push up deleted docs older than a certain point).
The latter of these options is significantly more complex than the former.

Azure Mobile Service concurrency handling in SQL?

I am implementing an Azure Mobile Service and I have a set of objects that can be accessed by multiple users, potentially at the same time. My problem is that I can't really find a lot of information on how to handle the potential concurrency issues that might result from this.
I know "Azure Tables" implements an E-Tag check. Is there an out-of-the-box solution for Azure Mobile Services for this one with SQL ? If not, what is the approach I should be going for here.
Should I just implement the E-Tag check by hand? I could include a GUID of the object that is generated every time the object is saved and checked when saving. This should be relatively safe way to do it?
For conflicts between multiple clients, you would need to add a detection/resolution mechanism. You could use a "timestamp" (typically a sequentially incremented version number) in your table schema and check it in your update script. You could fail an update if the timestamp used by a client for reading is older than the current timestamp.
If you want to use ETags via http headers, you could use Custom APIs. We are looking into enabling CRUD scripts to also set headers but that is not available today. Separately, we are looking into the offline scenarios as well.
(Prog Manager, Windows Azure Mobile Services)

Standard practice/API for sharing database data without giving direct database access

We would like to give some of our customers the option to read data from our central database. The data is live and new records are being added every few seconds. Our database is MySQL running on Amazon RDS.
I was wondering what is the common practice for doing so.
One option would be to give them select right from specific tables, in that case they would be able to access other customers' data as well.
I have tried searching for database, interface, and API key words and some other key words, but I couldn't find a good answer.
Thanks!
Use REST for exposing specific tables to do CRUD operations. You can control the access on it too.

Access Cloudant database from multiple applications

I would like to connect to the same database on Cloudant with different applications. Only one of the applications is going to be writing to the database, and the other would be reading only.
Is this okay to do?
Yep! Perfectly OK.
As Kim mentioned, the only thing to worry about with multiple asynchronous connections comes from when different applications / clients try updating the same doc. When this happens, Cloudant will create a conflict, storing both updates so you can sort out which is correct.
Check out Conflict Management in CouchDB for why this occurs and how to deal with it, and the Cloudant docs on conflicts for methods to examine conflicts.

Resources