[JAVA-1689] Why not provide a constructor with a String-Multi hosts? Created: 16/Mar/15  Updated: 11/Sep/19  Resolved: 17/Mar/15

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: yangyameng Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Now, I put mongo.host1,mongo.host2,mongo.host3 ... in my db.properties file,and config the MongoClient bean in beans.xml of Spring, like this:
<bean id="mongoClient" ..>
<constructor-arg>
<list>
<bean id="m1" ../>
<bean id="m2" ../>
<bean id="m3" ../>
</list>
</bean>
if I add/remove host, I must change the two files,
So, why not we provide a constructor with one String param and parse it in method?

Thanks~



 Comments   
Comment by yangyameng [ 18/Mar/15 ]

Thank u very very very much~~

and apologize for my unknowing...

Comment by Ross Lawley [ 17/Mar/15 ]

Hi yyam,

Thanks for the ticket, currently the preferred way for multiple hosts is either to use a MongoClientURI which is fully parsed or alternatively you can provide a list of ServerAddress to create the MongoClient instance.

Depending on your needs you should be able to parse a single list either by using a MongoClientURI or by building a list of ServerAddresses. Either way should be achievable by only setting the hosts in a single place but it might depend on how your application is configured and which libraries you are using.

For future, the best place for questions regarding MongoDB usage or the Java driver specifics is the mongodb-user mailinglist or stackoverflow as you will reach a boarder audience there, who may have already have a solution for this issue.

Regards,

Ross

Generated at Thu Feb 08 08:55:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.