0

I'm new(ish) to coding and new to Node.js. I am also new to Macs and its all a bit confusing. I am trying to install Mongodb.

I have successfully installed mongodb into my project folder using

npm install -s mongodb

I am following a tutorial video which makes this a little frustrating.

I have tried to connect to my database (which is being hosted on mlab) using:

var mongoose = require('mongoose')
var dbUrl = 'mongodb://user:user@ds119070.mlab.com:19070/runticle'

mongoose.connect(dbUrl, (err) => {
    console.log('mongo db connection', err)
})

When I run the code, I get the message

mongo db connection { MongoNetworkError: failed to connect to server [ds119070.mlab.com:19070] on first connect [MongoNetworkError: connect ECONNREFUSED 54.72.66.253:19070]
    at Pool. (/Users/alfie/Desktop/code/Lindacourse/mygod/node_modules/mongodb-core/lib/topologies/server.js:505:11)
    at emitOne (events.js:116:13)
    at Pool.emit (events.js:211:7)
    at Connection. (/Users/alfie/Desktop/code/Lindacourse/mygod/node_modules/mongodb-core/lib/connection/pool.js:329:12)
    at Object.onceWrapper (events.js:317:30)
    at emitTwo (events.js:126:13)
    at Connection.emit (events.js:214:7)
    at Socket. (/Users/alfie/Desktop/code/Lindacourse/mygod/node_modules/mongodb-core/lib/connection/connection.js:245:50)
    at Object.onceWrapper (events.js:315:30)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
  name: 'MongoNetworkError',
  message: 'failed to connect to server [ds119070.mlab.com:19070] on first connect [MongoNetworkError: connect ECONNREFUSED 54.72.66.253:19070]' }
(node:7587) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [ds119070.mlab.com:19070] on first connect [MongoNetworkError: connect ECONNREFUSED 54.72.66.253:19070]
    at Pool. (/Users/alfie/Desktop/code/Lindacourse/mygod/node_modules/mongodb-core/lib/topologies/server.js:505:11)
    at emitOne (events.js:116:13)
    at Pool.emit (events.js:211:7)
    at Connection. (/Users/alfie/Desktop/code/Lindacourse/mygod/node_modules/mongodb-core/lib/connection/pool.js:329:12)
    at Object.onceWrapper (events.js:317:30)
    at emitTwo (events.js:126:13)
    at Connection.emit (events.js:214:7)
    at Socket. (/Users/alfie/Desktop/code/Lindacourse/mygod/node_modules/mongodb-core/lib/connection/connection.js:245:50)
    at Object.onceWrapper (events.js:315:30)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
(node:7587) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7587) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

When I try to run mongod on my terminal, it says command not found.

David Makogon
  • 69,407
  • 21
  • 141
  • 189
  • 1
    You can't run `mongod` unless you've installed the actual MongoDB database engine (and the `npm` module only installs the library for you to programmatically connect to MongoDB, so that doesn't install MongoDB itself). – David Makogon May 11 '18 at 11:48
  • @DavidMakogon Ah thank you, so that explains why I can't run it. Would you recommend I download the database engine instead of trying to use mlab? Easier to connect? –  May 11 '18 at 11:55
  • Also being marked as a duplicate may be fair but having read that post already, I still haven't a clue what is wrong and what I should do... I am not using home-brew either! –  May 11 '18 at 11:58
  • I didn’t close your question, so I can’t speak to the duplicate. You can certainly work with mongodb locally for dev/test, but that won’t help you in a production environment. – David Makogon May 11 '18 at 12:06

0 Answers0