title: How to dynamically create MongoTemplate instances, with credentials?
body: <p>Prior to Spring Data MongoDB 1.9.0-RELEASE, I was able to create a MongoTemplate object as follows:
  <code>new MongoTemplate(client, dbName, credentials)</code>.  Upon upgrading, this constructor no longer works, giving an error to use <code>MongoCredential</code> instead.  However, there is no similar <code>MongoTemplate</code> constructor that uses <code>MongoCredential</code>.  It appears that the only way to specify credentials now is when constructing the <code>MongoClient</code> object.  </p>
  
  <p>However, since my app is multitenant on the database level, this doesn't work because it does not allow for additional credentials to be added after construction (meaning <code>MongoTemplate</code>s cannot be created dynamically).  It also is not ideal because if any of the credentials in the list are bad, none of the database connections work, as opposed to just the one with bad credentials.</p>
  
  <p>I also do not want to create a new <code>MongoClient</code> instance for each database.  From what I understand, doing so would create a new connection for each database rather than letting <code>MongoClient</code> manage a connection pool, which is ultimately not sustainable since Mongo only allows a finite number of connections.</p>
  
  <p>Do I have any options here besides continuing to use the outdated library?</p>