Is there a way to clear MongoDB collection for a specific rate limiter programatically? #159
-
Hi! First of all, thank you for the great library! I have the next question "Is there a way to clear all data from a collection for a specific rate limiter"? For example, I've created the next limiter:
Now I have this collection("rate_limiter_base") in my DB, and after some time I would like to clear all data from this collection using something like this:
But unfortunately, I couldn't find a similar API, so could you please help and tell me if there is a way to do this somehow? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, thank you. The code to delete all documents from collections: connection.collection(baseLimiter.tableName).deleteMany({}) Note, all expired documents removed from a collection automatically with expiring index built for every collection by |
Beta Was this translation helpful? Give feedback.
Hi, thank you.
There is no built-in method to clean up a collection.
There is collection.deleteMany({}) in mongodb package for that. For the
deleteMany
method you'd need a collection name, which can be got from baseLimiter likebaseLimiter.tableName
.The code to delete all documents from collections:
Note, all expired documents removed from a collection automatically with expiring index built for every collection by
expire
.