title: MongoDB C# Driver connection pooling
body: <p>I'm using the current stable version of the MongoDB C# Driver. I have a long-running service essentially reads data from an external source and writes it all to a MongoDB database. </p>
  
  <p>At the moment, I handle this by connecting to MongoDB on startup...</p>
  
  <pre><code>void Connect()
  {
      var client = new MongoClient("(url)");
      var server = client.GetServer();
      var db = server.GetDatabase("(db-name)");
      this.coll = db.GetCollection("(collection-name)");
  }
  </code></pre>
  
  <p>and then whenever I get some data, I simply do:</p>
  
  <pre><code>void Insert(object data)
  {
      this.coll.Save(data);
  }
  </code></pre>
  
  <p>This all works fine, except for the odd occasion where the connection to MongoDB fails. I then an IOException on the Save call.</p>
  
  <p>So I want to add some resilience to this, and the natural thing to do is to catch the IOException, try to re-connect, and then retry the Save. However, I'm wondering if I can make use of the connection pool to automatically handle lost connections for me. If so, what would my code need to look like for connection pooling to work?</p>