New API Method to GetServer() ?

294 views
Skip to first unread message

sallgeud

unread,
May 12, 2015, 11:58:35 AM5/12/15
to mongod...@googlegroups.com
The GetServer() method appears deprecated. We're interested in continuing to utilize the "Ping" functionality and would like it to possibly be extended to the MongoClient or cluster. If GetServer() is deprecated... what is the alternate method of getting a specific server from a client?

Craig Wilson

unread,
May 12, 2015, 12:19:29 PM5/12/15
to mongod...@googlegroups.com
You can get a database and use the RunCommandAsync method to run the ping command (http://docs.mongodb.org/manual/reference/command/ping/). However, it doesn't sound like that is what you really want to do. Could you perhaps indicate what your intent is and I can help you do that in the new API.

Craig

sallgeud

unread,
May 12, 2015, 1:09:22 PM5/12/15
to mongod...@googlegroups.com
There are certain situations where we want to check if the server is running prior to attempting a query in order to properly handle fail over.  We basically have a monitoring service that will give us notification of when connections are down and at least make an attempt to reconnect on a schedule.  This may be less necessary now, as we don't appear to have the issues we once did when rs.stepDown was executed. 


On Tuesday, May 12, 2015 at 10:58:35 AM UTC-5, sallgeud wrote:

Craig Wilson

unread,
May 12, 2015, 2:16:41 PM5/12/15
to mongod...@googlegroups.com
So, if you want to be bullet proof, then you really need to connect directly to each of your nodes separately and run a simple ismaster command or a ping command on them.  MongoClient has a property called Cluster (http://api.mongodb.org/csharp/2.0/html/P_MongoDB_Driver_MongoClient_Cluster.htm) which provides a description of the current topology. You can explore that as it might solve your immediate problem. It is updated every 10 seconds when all is well, and much quicker when a node is down.

Craig

sallgeud

unread,
May 12, 2015, 3:41:34 PM5/12/15
to mongod...@googlegroups.com
Sounds good. Our primary remaining use after some cleanup is to verify that if we add or change a list of databases (in our administrative panel), that we do not commit the changes until we verify that server actually exists, whether it has any databases is irrelevant, so ping seemed most practical.

Craig Wilson

unread,
May 12, 2015, 4:00:52 PM5/12/15
to mongod...@googlegroups.com
Ok. Make sure that you are still handling errors properly. Between the time you ping the server and issue the commands, it might go down. Also, any number of network conditions may cause a failure.

Craig
Reply all
Reply to author
Forward
0 new messages