Deleting large number of documents in single query results in seemingly erroneous response error even though the query is successful

Hi @alexmaughan and welcome!

It looks like this got taken care of in Discord, so I want to close the loop here.

It’s possible that this is related to the maximum transaction size limit: Transaction exceeded limit: got 24179504, limit 16777216 - #23 by Daniel_Steigerwald

Additionally, deleting each document encurs at least 1 Write Op. Due to the transaction size limit and the cost, it could be beneficial for cost to delete the Collection and recreate it.

Unfortunately, you cannot delete a Collection and immediately create another with the same name. As you suggested in Discord, you can work around this by adding versioning to the Collections’ names. Another caveat to deleting a Collection, is that doing so will also delete the Indexes associated with the Collection. That means you may have to version Index names as well.

If you still prefer to delete the individual Documents, then it may be helpful to use pagination. This would be the recommended best practice to working on 1000’s of Documents anyway, regardless of the transaction size limit. There is little cost benefit (In terms of Read/Write/Compute Operations) to performing a query on 10000 Documents in one query than there is splitting it into separate requests. In fact, big queries on so many documents increase the query execution time, so increase the chance of timeouts and contention with other queries. The balance of performance and page-size also depends on your users’ reliable access to the internet, how much you need to limit network traffic. And of course, it may be critical to complete more work within a single transaction to guarantee some function of your application.

Several drivers, including the JS driver, have pagination helpers that at least make the code easy to split work into smaller chunks.