added check for an open MongoDB connection