Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to delete a specific cosmosdb document or batch deletes throught the library? #443

Open
zhong0x opened this issue Mar 9, 2021 · 1 comment

Comments

@zhong0x
Copy link

zhong0x commented Mar 9, 2021

No description provided.

@aczelandi
Copy link

@zhong0x - That's an interesting question, I was wondering about this myself.
The only workaround I found was to use the Time To Live (TTL) capability of Cosmos DB. Basically by enabling TTL on the container level and setting the 'ttl' field of an existing item to a very small value, will do the trick.

To enable TTL on container level follow this tutorial.

Afterwards you could read the records that you want to delete using:

val recordsToDelete = spark.read.cosmosDB(yourCosmosDbReadConfig)

Then you could force the value of TTL to 1 and write the records back.

val recordsMarkedForDeletion = recordsToDelete.withColumn("ttl", lit(1)) recordsMarkedForDeletion.write.mode(SaveMode.Overwrite).cosmosDB(yourCosmosDbWriteConfig)

The above snippet will ensure the deletion of the selected items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants