Skip to content

Auto-configuration for Spring Data MongoDB ignores spring.data.mongodb.database when spring.data.mongodb.uri has been set #35566

@code-uri

Description

@code-uri

After upgrading to spring-boot 3 mongo auto configuration is not working, when connection string is used.

I think we need to have a fallback option if this.connectionDetails.getConnectionString().getDatabase() is null.

@Bean
@ConditionalOnMissingBean(ReactiveMongoDatabaseFactory.class)
public SimpleReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory(MongoClient mongo) {
	return new SimpleReactiveMongoDatabaseFactory(mongo,
			this.connectionDetails.getConnectionString().getDatabase());
}

Can we change the above code as mentioned below?

@Bean
@ConditionalOnMissingBean(ReactiveMongoDatabaseFactory.class)
public SimpleReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory(MongoProperties properties,         MongoClient mongo) {
        String database = this.connectionDetails.getConnectionString().getDatabase();
        if(database==null)
            database = properties.getDatabase()
		return new SimpleReactiveMongoDatabaseFactory(mongo,
			database);
}

Metadata

Metadata

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions