Skip to content

Is there a way to clear MongoDB collection for a specific rate limiter programatically? #159

Answered by animir
yaroslav-perec asked this question in Q&A
Discussion options

You must be logged in to vote

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 like baseLimiter.tableName.

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 expire.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@yaroslav-perec
Comment options

Answer selected by yaroslav-perec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants