[JAVA-519] MongoDB's connection is not a effective connection to a MongDB server where new Mongo(serverAddressList) Created: 11/Feb/12 Updated: 19/Oct/16 Resolved: 15/May/12 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | 2.6.5, 2.7.2 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | xfc | Assignee: | Jeffrey Yemin |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | check, connection, mongodb, start | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
Here is our code to start mongoDB:
I find that Mongo instance does not check master; The code of checking master is in Upate class:
The checkMaster method code is in DBTcpConnection:
So,there are two problem: First is:if I want to check master in staring my web applcation,I just have no choice; Second is: The Mongo object instance actually represents a pool of connections to the database,this thing is not any valuable if we don't check master; I suggest that you can make checkMaster method publicly or get us a button is check master. |
| Comments |
| Comment by Jeffrey Yemin [ 15/May/12 ] | |||||||
|
This is an edge case and the workaround is acceptable, so we're not going to make an API change for it. | |||||||
| Comment by xfc [ 16/Feb/12 ] | |||||||
|
The server has a "ping" command that makes more sense to use than DB.getCollectionNames:
Re:
because,we all just use its DBTCPConnector's checkMaster method. We can add a helper function to make that less verbose, if it works for you. Re:thank you~ | |||||||
| Comment by Jeffrey Yemin [ 13/Feb/12 ] | |||||||
|
The server has a "ping" command that makes more sense to use than DB.getCollectionNames:
We can add a helper function to make that less verbose, if it works for you. | |||||||
| Comment by xfc [ 12/Feb/12 ] | |||||||
|
The Mongo constructor is currently designed not to actually connect to the server or to throw exceptions as those could happen during any operation later. Can you give us a button to decide whether we need actually connection to the server. We just want to check master in our starting web application. A full client code example: public class MongoDataSource { private static Logger log = LoggerFactory.getLogger(MongoDataSource.class); public MongoDataSource(String replicaHosts, String dbName, String writeConcernName, boolean slaveOk,boolean checkMaster){ this.dbName = dbName; public void init() throws UnknownHostException, MongoException { mongo = new Mongo(hosts); if (checkMaster) { db.getCollectionNames(); }} public void destroy() { mongo.close(); }} configuration in spring xml file: | |||||||
| Comment by Scott Hernandez (Inactive) [ 11/Feb/12 ] | |||||||
|
Can you post a full client code example with a note where you expect things to be different including the WriteConcern you are using? The Mongo constructor is currently designed not to actually connect to the server or to throw exceptions as those could happen during any operation later. | |||||||
| Comment by xfc [ 11/Feb/12 ] | |||||||
|
now,my way to resolve this problem: The sqequnce of invoking class: |