Problem connecting to my mongo database

0

If I try to connect to mongo, mongod from the shell I get that and in my configuration my connection to mongo also gives me error

MONGO 

MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
2018-07-05T12:05:35.086+0200 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket forerror after poll), reason: Connection refused
2018-07-05T12:05:35.088+0200 E QUERY   [thread1] Error: couldn't connectto server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed

MONGOD 

  14_companies_class_team git:(maste
r) ✗ mongod2018-07-05T12:07:05.183+0200 I CONTRO
L  [initandlisten] MongoDB starting : pid=5685 port=27017 dbpath=/data/db
64-bit host=Franciscos-MacBook-Pro.local2018-07-05T12:07:05.183+0200 I CONTRO
L  [initandlisten] db version v3.4.102018-07-05T12:07:05.183+0200 I CONTROL  [initandlisten] git version: 078f2
8920cb24de0dd479b5ea6c66c644f6326e92018-07-05T12:07:05.184+0200 I CONTRO
L  [initandlisten] OpenSSL version: OpenSSL 1.0.2l  25 May 20172018-07-05T12:07:05.184+0200 I CONTROL  [initandlisten] allocator: system2018-07-05T12:07:05.184+0200 I CONTRO
L  [initandlisten] modules: none2018-07-05T12:07:05.184+0200 I CONTROL  [initandlisten] build environment:2018-07-05T12:07:05.184+0200 I CONTROL  [initandlisten]     distarch: x86_642018-07-05T12:07:05.184+0200 I CONTROL  [initandlisten]     target_arch: x86_642018-07-05T12:07:05.184+0200 I CONTRO
L  [initandlisten] options: {}2018-07-05T12:07:05.184+0200 I -   [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2018-07-05T12:07:05.184+0200 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statis
tics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),s
tatistics_log=(wait=0),2018-07-05T12:07:05.186+0200 E STORAGE  [initandlisten] WiredTiger error (
13) [1530785225:186114][5685:0x7fffa660d340], file:WiredTiger.wt, connection: /data/db/WiredTiger.turtle: handl
e-open: open: Permission denied2018-07-05T12:07:05.197+0200 I -   [initandlisten] Assertion: 28595:1
3: Permission denied src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.
cpp 2762018-07-05T12:07:05.197+0200 I STORAGE  [initandlisten] exception in initA
ndListen: 28595 13: Permission denied, terminating
2018-07-05T12:07:05.198+0200 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2018-07-05T12:07:05.198+0200 I NETWORK  [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2018-07-05T12:07:05.198+0200 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2018-07-05T12:07:05.198+0200 I CONTROL  [initandlisten] now exiting
2018-07-05T12:07:05.198+0200 I CONTROL  [initandlisten] shutting down with code:100


DB CONNECTION JS

const mongoose = require('mongoose');
const DB_NAME = 'companies-clase';
const DB_URI = 'mongodb://localhost/${DB_NAME}';

mongoose.connect(DB_URI)
.then(() => {
    console.info('Connected to database');
})
.catch(error => {
    console.log(error);
});


CONNECTING TO MONGO DB

{ MongoNetworkError: failed to connec
t to server [localhost:27017] on firs
t connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
    at Pool.<anonymous> (/Users/franciscomanriquedelara/DEV/04_IRON HACK/03_MODULE-2/HOMEWORK/14_companies_class_team/node_modules/mongodb-core/lib/topologies/server.js:505:11)
    at Pool.emit (events.js:182:13)
    at Connection.<anonymous> (/Users/franciscomanriquedelara/DEV/04_IRONHACK/03_MODULE-2/HOMEWORK/14_companies_class_team/node_modules/mongodb-core/lib/connection/pool.js:329:12)
    at Object.onceWrapper (events.js:273:13)
    at Connection.emit (events.js:182:13)
    at Socket.<anonymous> (/Users/franciscomanriquedelara/DEV/04_IRON HACK/03_MODULE-2/HOMEWORK/14_companies_class_team/node_modules/mongodb-core/lib/connection/connection.js:245:50)
    at Object.onceWrapper (events.js:273:13)
    at Socket.emit (events.js:182:13)
    at emitErrorNT (internal/streams/destroy.js:82:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  name: 'MongoNetworkError',
  message:
   'failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]' }
    
asked by Francisco Manrique de lara 05.07.2018 в 12:10
source

1 answer

0

Make sure the port is not busy or the firewall blocks you.

If this does not work for you, do the following:

delete the lock file with the following command:

sudo rm /var/lib/mongodb/mongod.lock 

repair mongodb:

mongod –repair

start mongodb:

sudo systemctl start mongodb

start the mongo client:

mongo
    
answered by 21.10.2018 в 08:29