0

i am trying for the firsttime, to connect to mongodb. and i get the exception and so connectiion is refused. I am using SprintBoot3.0 and below are the Maven Depedencies.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.0.4</version>
 </parent>
<groupId>com.sbProject</groupId>
<artifactId>ProductService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ProductService</name>
<description>ProductService</description>
   <properties>
    <java.version>17</java.version>
</properties>
<dependencies>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>

/*****in the application.properties file, i hav tried both ways *****/

spring.data.mangodb.uri=jdbc:mongodb://localhost:27017/product

#spring.data.mongodb.host=localhost

#spring.data.mongodb.port=27017

#spring.data.mongodb.database=product

Please help.

  • I suspect `localhost` is translated to an IPv6 address on your system. You could check `mongod.log` for the error to learn why the connection was rejected. If `localhost` is translated to `::1`, you could enable IPv6 in the MongoDB server, or more simply use `127.0.0.1` rather than `localhost`. – rickhg12hs Mar 12 '23 at 14:42
  • Please edit the question to add the full exception – Joe Mar 13 '23 at 07:09

0 Answers0