CouchDB replicate without deleting documents - couchdb

Hi: I want to use a mobile CouchDB and a remote CouchDB. To transfer from mobile to remote DB I want to replicate the data. But for storage reasons I want to regularly delete old data from the mobile CouchDB and keep it on the remote CouchDB. As what I have seen local deletion will also be replicated. Is there any knowledge about how to handle this?

You should be able to use filtered replication, http://wiki.apache.org/couchdb/Replication#Filtered_Replication, with a filter function of:
function(doc) {
return !doc._deleted;
}

Related

Listen to changes of all databases in CouchDB

I have a scenario where there are multiple (~1000 - 5000) databases being created dynamically in CouchDB, similar to the "one database per user" strategy. Whenever a user creates a document in any DB, I need to hit an existing API and update that document. This need not be synchronous. A short delay is acceptable. I have thought of two ways to solve this:
Continuously listen to the changes feed of the _global_changes database.
Get the db name which was updated from the feed.
Call the /{db}/_changes API with the seq (stored in redis).
Fetch the changed document, call my external API and update the document
Continuously replicate all databases into a single database.
Listen to the /_changes feed of this database.
Fetch the changed document, call my external API and update the document in the original database (I can easily keep a track of which document originally belongs to which database)
Questions:
Does any of the above make sense? Will it scale to 5000 databases?
How do I handle failures? It is critical that the API be hit for all documents.
Thanks!

Multiple PouchDB to single CouchDB

I need to submit data from multiple mobile apps. in my mobile app I am planning to use pouchdb to store the document, later I want this document to sync to couchdb one-way only.
what will happen if I submit data from multiple devices ? will pouch db create same document ID and overwrite data in couchDB ?
The document ID will not be the same, assuming you're letting PouchDB create them (the likelihood of PouchDB generating the same ID twice is extremely low)

Pouch to couch sync

I am making an application using Ionic framework We are using Couchdb and pouchdb but when we do couchdb to pouchdb sync All the documents in Couchdb are replicating to every pouchdb user I am stucked please help me
You need to create a filtered function to replicate only documents you need.
Here the documentation from pouchdb: http://pouchdb.com/2015/04/05/filtered-replication.html
Usually for this case I create one database per user in couchdb and I replicate pouchdb only with the couchdb user database. So you don't have to deal with filtered function on pouchDB.
You will use filtered function to replicate couchdb user database to a master couchdb database.
Here the documentation for couchDB replication with filtering function: https://wiki.apache.org/couchdb/Replication#Filtered_Replication
I think your question is answered in that thread:
here
Good luck

PouchDB - start local, replicate later

Does it create any major problems if we always create and populate a PouchDB database locally first, and then later sync/authenticate with a centralised CouchDB service like Cloudant?
Consider this simplified scenario:
You're building an accommodation booking service such as hotel search or airbnb
You want people to be able to favourite/heart properties without having to create an account, and will use PouchDB to store this list
i.e. the idea is to not break their flow by making them create an account when it isn't strictly necessary
If users wish to opt in, they can later create an account and receive credentials for a "server side" database to sync with
At the point of step 3, once I've created a per-user CouchDB database server-side and assigned credentials to pass back to the browser for sync/replication, how can I link that up with the PouchDB data already created? i.e.
Can PouchDB somehow just reuse the existing database for this sync, therefore pushing all existing data up to the hosted CouchDB database, or..
Instead do we need to create a new PouchDB database and then copy over all docs from the existing (non-replicated) one to this new (replicated) one, and then delete the existing one?
I want to make sure I'm not painting myself into any corner I haven't thought of, before we begin the first stage, which is supporting non-replicated PouchDB.
It depends on what kind of data you want to sync from the server, but in general, you can replicate a pre-existing database into a new one with existing documents, just so long as those document IDs don't conflict.
So probably the best idea for the star-rating model would be to create documents client-side with IDs like 'star_<timestamp>' to ensure they don't conflict with anything. Then you can aggregate them with a map/reduce function.

Cloudant and local CouchDB installation 2 way replication

I'm trying to sync a database in a local CouchDB installation (v 1.3.1 on a Mac) and a database on Cloudant with master-master replication.
In my local Futon http://localhost:5984/_utils I've configured Replicator to replicate my local database to Cloudant. Everything works fine replicating from the local database to the Cloudant one, but not backwards. If data changes in the Cloudant's database those changes are not been replicated to my local database.
Local -> Cloudant = works
Cloudant -> Local = doesn't work
Is this possible to be made? Can anyone help?
Thanks!
Finally I figured out that I only needed to configure two replications from my local CouchDB.
Here are both replications:
{
"source":"https://username:pwd#username.cloudant.com/cloud_db",
"target":"http://username:pwd#localhost:5985/local_db"
}
{
"source":"http://username:pwd#localhost:5985/local_db",
"target":"https://username:pwd#username.cloudant.com/cloud_db"
}
Now, in http://localhost:5984/_utils/status.html there are two replications running.
Note that I added the username and password to the local connection too. That's because you need to be an authorized user in order to replicate design documents.
Thanks a lot Mike, your answer helped a lot!
Can you try specifying full URLs for both source and target? I think it would look like:
#create the replicator database for your local server
curl -X PUT 'http://127.0.0.1:5984/_replicator'
then upload this document:
{
"source":"https://username:pwd#username.cloudant.com/source_db",
"target":"http://127.0.0.1:5985/target_db"
}
Then you should be able to monitor that by a:
http://127.0.0.1:5984/_active_tasks
If that doesn't work for you, can you please copy/paste:
the body of the document in the _replicator database
grep the log file for anything with _replication
Also, there's a classic 'gotcha' here, that I think you need 'writer' permissions on both the source and target database. That may seem odd, but it's because the replicator is saving checkpoint documents on both the source and the target so that the next time you ask to replicate, it doesn't have to start from scratch.

Resources