How to wire in my remote mongo db to the example mongo project?

536 views
Skip to first unread message

Steve Schreiner

unread,
Jul 26, 2014, 1:22:39 PM7/26/14
to extdire...@googlegroups.com
How can I wire in my remote mongo db into the example mongo project (https://github.com/ralscha/eds-starter-mongodb)?  In a previous post you mentioned about putting it with the application.yml but I don't see it in the project?

spring:
  data:
    mongodb:
      uri: mongodb://

Thanks!


Ralph Schaer

unread,
Jul 26, 2014, 1:51:14 PM7/26/14
to extdire...@googlegroups.com
Hi.

Sorry I changed it to the properties format, because all the examples in the spring boot reference documentation are in this format. http://docs.spring.io/spring-boot/docs/1.1.4.RELEASE/reference/pdf/spring-boot-reference.pdf


You find the files here:
/eds-starter-mongodb/src/main/resources/application.properties
/eds-starter-mongodb/src/main/resources/application-development.properties

The first one is the default profile and is active when no profile is specified. 
The second file is activated with this system environment flag: -Dspring.profiles.active=development

Spring Boot supports these MongoDB properties:

spring.data.mongodb.host= # the db host
spring.data.mongodb.port=27017 # the connection port (defaults to 27107)
spring.data.mongodb.uri=mongodb://localhost/test # connection URL
spring.data.mongo.repositories.enabled=true # if spring data repository support is enabled

If you need more control you can specify a @Bean like the following example. This example changes the WriteConcern to UNACKNOWLEDGED. The default is ACKNOWLEDGED which waits for a response from the server.

        @Bean
public MongoClient mongo() throws Exception {
MongoClient mongoClient = new MongoClient("localhost");
mongoClient.setWriteConcern(WriteConcern.UNACKNOWLEDGED);
return mongoClient;
}




Ralph
Reply all
Reply to author
Forward
0 new messages