Completely remove document from server AND client

Hi !

I want to delete some documents that should not be used anymore. I tried to use the DELETE documents using the DELETE statement from N1QL command line and they are deleted from the server (or marked as tombstone) but once a client using couchbase lite (Android device here) is syncing with the database, it pushes all the deleted document to the remote server instead of deleting it in its local database.

Is their any way to delete documents remotely and propagate the deletion to every clients?

Thank’s for help !

You should use the sync gateway REST API to delete the.

Thank’s but the REST API accept only one document ID. Isn’t it possible to delete documents resulted from a query ? (I want to permanently delete every documents that has type “xxx”)?

You can use _bulk_docs to delete multiple docs; just set the new body of each doc to {"_deleted":true}. You’ll also have to include a _rev property matching the document’s current revision ID, as you would with any document update.

Remove document using code and push it. Do the deleting process in while loop. It will automatically delete it from Server.

Using _bulk_docs is the same problem, if I need to delete 1000 documents that result from a query like “select where type = x”, I won’t type every single document id by hand.

Using code seems the best approach but this doesn’t look very clean. I would have to code scripts every time I would like to delete documents based on a query.

But thank you for your answer !

1 Like

You can do one more thing, iterate all exclude the doc which u dnt want to delete…

let say u dnt want to delete doc where name is “xyz”.

Psudocode will be -

loop (all docs ){
delete doc
hope this will work for you

We don’t have any new solution for doing something like this yet?! Using code with REST API is not a clean and good solution ​for lots of documents!