Delete one by one or USE KEYS

A job needs to delete old documents. each batch it deletes about 200 documents. we have the document ids.
which way will be more efficient:

  • delete by query:
    delete from bucket use keys [… ids …]
    bucket->query(query)
  • one by one:
    loop through all ids and
    bucket->remove(id)

thanks in advance.

If you know document keys use bucket->remove(id)
You can do asynchronous and parallel too.

1 Like

Thank you @vsr1. I assume even with Use keys it still needs to be processed by query analyzer, but with remove(), it is just a key-value operation?

As long has you dont have any WHERE clause it is simple remove in loop.
If you have where clause it will do need to do fetch and remove.
NOTE: bucket.query() first need to send to to n1ql node and which need to remove from data nodes It is 2 hops operations.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.