I am using MongoDB with Java and have some problems and questions about my connection. First of all, how should I connect to Mongo? Should I use a static client and leave it open? Because it takes like 500ms to connect. So it isn't the best idea to always connect it when users want data, is it?
But the next problem is following. When I do some querys i get the error message java.lang.IllegalStateException: The pool is closed
or java.lang.IllegalStateException: state should be: open
.
So, how should I manage my whole MongoDB connection stuff? Always wait 500ms is way to slow and restart the server after like 10 connections isn't that good. Are there any other good ways?
Thank you for your help!