Error creating bean with name 'mongoDatabaseFactory' defined in class path resource. Failed to instantiate [org.springframework.data.mongodb.core.MongoDatabaseFactorySupport]: Factory method 'mongoDatabaseFactory' threw exception with message: Database name must not be empty
I’m not sure what I’m doing wrong here.
error message
application.properties
I can’t seem to figure out how to get rid of this message. I have a DB name set in the application.properties. I have MongoDB running and I’m still getting this every time I try to start my server.
2
Answers
Just your fellow learner here, following the same tutorial.
I jumped to the documentation and it seems you just have to add
/movie-api-db
at the end of your URI, to get access to the database collection:spring.data.mongodb.uri=mongodb+srv://<username>:<pwd>@<cluster>.mongodb.net/movie-api-db
Hope, it’ll help!
For anyone else using Springboot 3.1.0 specifically, there is a solution offered in the github issue here.
Basically,
spring.data.mongodb.database
is ignored if you’ve setspring.data.mongodb.uri
, which causes the error seen in the post. Adding the string template into the uri solves the issue.This has been fixed for version 3.1.1 which will be released at a later date.