Mongo connection/status check with Java driver

3,296 views
Skip to first unread message

jdr2000

unread,
Mar 24, 2011, 5:32:56 PM3/24/11
to mongodb-user
What would the preferred way to check the status of Mongo connection
(to a single or a replica set), using the Java driver? Ideally just a
Boolean type, something like "active?" in the Ruby driver.


Eliot Horowitz

unread,
Mar 25, 2011, 1:36:52 AM3/25/11
to mongod...@googlegroups.com
What exactly do you mean by status?
A Mongo instance internally has a connection pool and manages the
connections to make sure they are healthy.

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

jdr2000

unread,
Mar 25, 2011, 10:27:56 AM3/25/11
to mongodb-user

Just that the client connection to the cluster is active/responsive.
It could be as simple as a findOne call, or more like a nop. But I'm
figuring there's something in the driver that has been designed for
this purpose (maybe not?).

jdr2000

unread,
Mar 28, 2011, 4:15:06 PM3/28/11
to mongodb-user
I believe I solved this myself. My client app's
"isConnectedToMongo()" method performs as simple
db.getCollectionNames() call on the current database. If there are no
MongoExceptions, the method returns true, else the exception is caught
and returns false.

Other calls like db.getLastError() or db.isAuthenticated() would
probably work for my purposes, too.

Reply all
Reply to author
Forward
0 new messages