-
Notifications
You must be signed in to change notification settings - Fork 40.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using an empty string MongoDB 'replica-set-name' property will result in ClusterType=REPLICA_SET #42055
Comments
Courtesy of Google Translate: As shown in the code, not doing StringUtils.isBlank processing in the code will result in ClusterType=REPLICA_SET of ClusterSettings, which may have negative effects. |
@miaoGod I'm not sure we should make the change you're suggesting. We follow the same logic as the MongoDB driver (see https://github.com/mongodb/mongo-java-driver/blob/634fd094992f09cf39deec0ea2afeb12b4db61ef/driver-core/src/main/com/mongodb/connection/ClusterSettings.java#L621) which doesn't check for empty string. What triggered you to raise this issue? Have you actually tried to use a blank string in your own application? |
@philwebb 是的,我确实遇到了这种场景,详情如下: spring:
data:
mongodb:
replica-set-name: ${mongo.replicaSetName} 其中的mongo.replicaSetName引用的是application-{env}.properties中的配置 按照以上配置启动项目以后,我发现mongo.replicaSetName无论是否有值,ClusterSettings的ClusterType都会为REPLICA_SET, |
Translated: Yes, I did encounter this scenario, the details are as follows: Due to limited budget, the mongodb configuration in the test environment only has one instance, while the production configuration has two instances (one master and one slave). When using the master-slave replication configuration, I use the following code:
The After starting the project according to the above configuration, I found that regardless of whether But if I remove the replica-set-name configuration item directly instead of making it equal to an empty string, the |
That seems like a valid use-case. We'll fix this. |
spring-boot/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizer.java
Line 91 in 5490e73
如代码所示,不对代码做StringUtils.isBlank处理,会导致ClusterSettings的ClusterType=REPLICA_SET,这可能会产生负面影响。
The text was updated successfully, but these errors were encountered: