There is no point reinventing the wheel so I hunted for usage examples. I struggled to find any best practice implementation, so I decided to hack my own together.
A requirement I had was I had was I wanted to be able to deploy the web app to a range of different environments, so I needed the service to be flexible. The simplest way I could think of was pulling the config from the application's web.xml file.
The Mongo object instance represents a pool of connections to the database so you will only need one object of class Mongo even with multiple threads.
web.xml snippet:
MongoService snippet:
Then from the data access object you can specify and authenticate to the relevant DB.
XxxDAO snippet:
This has been working like a dream for me proving to be an extremely convenient way to easily connect to Mongo.