0

I need to delete specific documents from a cloudant database as illustrated below. All documents are in the Json format:

{
    "_id":"abcd",
    "_rev":"1_efgh",
    "moduleName":"co",
    "userid":"knight",
    "stateType":"yout"
}

I want to delete all the documents for which the "userid" field does not match any of the values in a list of String values, say ["userid1", "userid2"]

I am using com.cloudant.client.api.CloudantClient in Springboot.

  • As one solution, I have fetched all documents from the cloudant database as a list and iterated each document in the list to check for a match in the second list i.e, ["userid1", "userid2"]. And removed those documents that do not match _any_ of the values in the second list i.e, ["userid1", "userid2"]. Is there a better way to achieve this? – Hari Hara Sudhan A.K Sep 04 '20 at 17:29

1 Answers1

0

You can create a view to get the documents matching your criteria. Then you should perform a bulk operation to delete the docs you've fetched before. See also related question: How to delete docs in Couch db

bessbd
  • 570
  • 4
  • 17