2

I have just received an Android project that works with CouchDB and CouchBase Lite.

The first step in the app is a replication, more or less the replication spent more than 2 hours, but usually it never finish.

On the dataBase site I can see that doc_del_count is bigger than doc_count, It does not make sense because we never delete documents.
enter image description here

In this case the replication process handles 519695 documents and 498264 of them are deleted, so it is crazy

My questions are:
Why replication download doc_del_count if they are deleted documents?
How Can I see those deleted documents?
Can I removed all those doc_del_count? How?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
JoCuTo
  • 2,463
  • 4
  • 28
  • 44

1 Answers1

1

Why replication download doc_del_count if they are deleted documents?

Because deleted documents are never truly deleted in CouchDB. Instead, the _deleted field is set to true. This is primarily to allow proper synchronization where updates can happen in more than one place. Imagine that a document is deleted from one place, but updated to include new information in another. Which operation should take priority? CouchDB has no way of knowing, so it keeps both versions around, and lets the application designer handle conflict resolution as they see fit.

How Can I see those deleted documents?

Consult this answer for details, but the short answer is: include revs_info=true in your query per the documentation.

Can I removed all those doc_del_count? How?

You can compact the database, but this won't remove deleted documents, for reasons explained above.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • Muchas gracias @Flimzy I am getting a lot of troubles replicating 519695 documents – JoCuTo Jul 16 '17 at 11:13
  • @JeCuRo: Depending on your use case, [filtered replication](https://wiki.apache.org/couchdb/Replication#Filtered_Replication) might be an option for you. – Jonathan Hall Jul 16 '17 at 11:14
  • Yes I tried it, I have a filter that says: " just take documents for the device number 22 and 84" but nothing changes and still waiting hours for the replication ---- "filters": { "22": "function(doc, req) { if( 22 == doc.device_num )return true; if( 84 == doc.device_num )return true; return false; }", – JoCuTo Jul 16 '17 at 11:18
  • @JeCuRo If you want to filter out deleted documents, you should use a filter that excludes `_deleted: true`. – Jonathan Hall Jul 16 '17 at 11:19
  • gracias amigo, also tried :( "22": if( 22 == doc.device_num )return true;if (doc._deleted)return false; if( 84 == doc.device_num )return true; return false; }", but in this case I got and error in the replication and the replication stops – JoCuTo Jul 16 '17 at 11:23