I have interfaces extends from MongoRepository. They are using default database of mongodb. I would like to define the database name for the classes.
public interface CustomerRepository extends MongoRepository<Customer, String> {
...
}
How can I define it?
You just need to define respective mongobd properties in application.properties
file or if you want to yml syntax then define props in application.yml
. Under src/main/resources
, application.properties
should be there already.
application.properties
:
spring.data.mongodb.host=<hostname>
spring.data.mongodb.port=27017
spring.data.mongodb.database=<dbname>
spring.data.mongodb.username=<usernamr>
spring.data.mongodb.password=******
Or
application.yml
:
spring:
data:
mongodb:
host: <hostname>
port: 27017
database: <dbname>
username: <usernamr>
password: ******
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With