Hey gang, in this MongoDB tutorial for beginners, I’ll shows you how we can connect to MongoDB using ‘mongodb.connect’. To connect, we’ll need to pass the method a connection string which matches up to the location of our database.

+ Repo –
+ Atom editor –
+ Download GIT –
+ MongoDB –
+ Robomongo –

JS Playlist –

NODEJS Playlist –

ASYNC JS Playlist –

You can find more front-end development tutorials on CSS, HTML, JavaScript, jQuery, WordPress, Node.js & more on the channel homepage…


========== PSD to WordPress Playlist ==========

============ Node.js for Beginners Playlist =============

============== The Net Ninja =====================

For more front-end development tutorials & to black-belt your coding skills, head over to – or

================== Social Links ==================

Twitter – @TheNetNinja –


  1. connection error: { MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED]

  2. This is what I got when I run the file:
    (node:17788) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`.

  3. Hello Net Ninja, Thanks for your tutorials. My question is that how can i create my own repository…in this tutorial we are cloning from Git. At first i tried to install mongoose without cloning from git it was giving me a no repository warning. I really want to understand this part of the tutorial. Your response will be greatly appreciated .

  4. Hi Shaun, first thanks for all the great tutorials. Here is my question: after running the connection.js file everything seems to work fine. But when I use the terminal (linux) to log into mongo and I do a 'show dbs', the created 'testaroo' database doesn't show up. Any idea why or what is going on here? Thanks again, kind regards.

  5. i tried so many times but its shows an error like this

    C:datadbmongodb-playlist>node test1/connection.js
    connection has been terminated { MongoError: failed to connect to server [locahost:27017] on first connect [MongoError: getaddrinfo ENOTFOUND locahost locahost:27017]
    at Pool.<anonymous> (C:datadbmongodb-playlistnode_modulesmongodb-corelibtopologiesserver.js:328:35)
    at emitOne (events.js:96:13)
    at Pool.emit (events.js:188:7)
    at Connection.<anonymous> (C:datadbmongodb-playlistnode_modulesmongodb-corelibconnectionpool.js:280:12)
    at Connection.g (events.js:292:16)
    at emitTwo (events.js:106:13)
    at Connection.emit (events.js:191:7)
    at Socket.<anonymous> (C:datadbmongodb-playlistnode_modulesmongodb-corelibconnectionconnection.js:177:49)
    at Socket.g (events.js:292:16)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at connectErrorNT (net.js:1021:8)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
    name: 'MongoError',
    message: 'failed to connect to server [locahost:27017] on first connect [MongoError: getaddrinfo ENOTFOUND locahost locahost:27017]' }

  6. hey yo, started watching your node.js and mongodb series this weekend and i am really thankful for your tutorial. stay awesome!
    btw i am really curious what font you are using in this tutorial. would be cool if you could answer <.<

  7. how come you attached the callbacks after attempting to make the connection? Would it be possible for the connection to be made BEFORE those callbacks are attached?

  8. Having to start mongo in the terminal with mongod command, open another shell, cd to mongdb-playlist and then enter node test/connection.js to get it working. Is this the correct way or another way around it…otherwise getting the error you force create with localhostp


Please enter your comment!
Please enter your name here