Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Completed
Created by Guest
Created on Aug 11, 2022

Create a close method on the MongoClient.

I have run into a situation where threads are not being garbage collected and are causing a serious issue. When we create a database for a specific user, we generate the users’ credentials inside of that database with access only to that database. The problem arises when we need to delete the user and database. The user sometime in the past connected to MongoDB using their credentials which leaves behind an open thread to the MongoDB that is logging into MongoDB once a minute with that users’ credentials. We then come along with our Admin user account and delete the user from the database and then delete the database. This causes the open thread using the now deleted user to start retrying to login using the now deleted users’ credentials over and over every .015 seconds. Our log file store area, about 30Gb fills up within a day with the MongoDB log spew. We need a way to kill a thread once its job is complete, so we don’t get into these runaway situations. I have read that other MongoDB drivers, namely the Java driver, can close the MongoClient. The C# Driver needs the same functionality desperately.Another option is to have the MongoClient stop the thread after 5 try's when the error coming back is user not found.
  • ADMIN RESPONSE
    Oct 18, 2025
    MongoClient is now disposable in 3.0 as seen in this ticket (https://jira.mongodb.org/browse/CSHARP-3431) which can allow this implementation.
  • Guest
    Dec 24, 2024
    MongoClient is now disposable in 3.0 as seen in this ticket (https://jira.mongodb.org/browse/CSHARP-3431) which can allow this implementation.