Search code examples
javamongodbdaomongo-java

Should my MongoDB DAOs request unique DB objects?


I'm using the standard MongoDB Java driver to roll my own DAOs. I'm aware that all of my DAOs can share the same Mongo instance, but should all of my DAOs accessing the same database share the same DB object or are there good reasons for a new DB object to be requested or each?

Thanks!


Solution

  • You can use shared instances of the Mongo class, the DB class and the DBCollection class if that proves to be practical for you. Whether or not you want to from a design perspective is up to you. I'd definitely use Mongo instances as singletons since they're relatively heavy weight (have their own thread pool etc.)