mongoDB, connection refused

There could be several reasons of it , which in short can be concluded as Your Application is unable to Communicate mongoDB service

1.Check your MongoDB using the same IP configured in your application.yml file, If not then configure the same used by MongoDB:

spring:
  profiles:
    active: dev
---
  spring:
    profiles: dev
    data:
      mongodb:
        host: localhost
        port: 27017

Here i assumed my mongo running on localhost, and port 27017, so i configured accordingly.

  1. Check whether your MongoDB service up and running , How to check ? Execute following command in your terminal

sudo service mongodb status

   <pre><code>
    ● mongodb.service - An object/document-oriented database
   Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2020-07-03 20:10:15 IST; 1min 54s ago
     Docs: man:mongod(1)
 Main PID: 14305 (mongod)
    Tasks: 23 (limit: 4915)
   CGroup: /system.slice/mongodb.service
           └─14305 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf</pre></code>

If Status not visible as active and running, you need to start/restart the service

sudo service mongodb restart


By default MongoDB only binds to the loopback interface which makes it only accessible from localhost. To change that you need to edit this line in mongod.conf file;

# /etc/mongod.conf

# Listen to local interface only. Comment out to listen on all interfaces.
bind_ip = 127.0.0.1

you can change it to bind_ip = 127.0.0.1,192.168.1.102 to allow LAN and local connections or you can remove or comment out that line to allow all connections.

For more info : MongoDB – Allow remote access

Tags:

Java

Mongodb