spring-guides / gs-accessing-data-mongodb

Accessing Data with MongoDB :: Learn how to persist data in MongoDB.
http://spring.io/guides/gs/accessing-data-mongodb/
Apache License 2.0
139 stars 161 forks source link

Could you help tell me how can I modify the mongo db server connection info? #18

Closed jeffyding closed 7 years ago

jeffyding commented 7 years ago

Hi: Follow the example, default mongo connection is localhost:27017, but I have standalone mongo server, so how can I modify the mongo db server connection info?

PS: I am using spring core not spring-boot, so I have to manually initailize mongo info, I am using Java config instead of xml config, could you help tell me how to use @EnableMongoRepositories, do you have some examples? appreciated! thanks!

jeffyding commented 7 years ago

I add application.properties into source folder, the content is:

MONGODB (MongoProperties)

spring.data.mongodb.database=test spring.data.mongodb.host=172.16.1.231 spring.data.mongodb.port=27017

That works now.

So this still works under spring-boot env, I want to use @Configuratin @EnableMongoRepositories, wish to see the demos...

mp911de commented 7 years ago

If you're using plain Spring with Spring Data MongoDB, then the configuration is up to you. Spring Data MongoDB provides an abstract base class (AbstractMongoConfiguration) that contains the essential bits to set up the necessary infrastructure.

Take a look at the reference documentation which contains some examples. Basically you need to provide an instance of Mongo (MongoClient for the 3.x driver) that contains endpoint details.