Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/The best guide for fixing ''mongoerror: failed to connect to server [localhost:27017] on first connect'' error.
Next
Answered
shanestrackejr
  • 3
shanestrackejr
Asked: June 27, 20222022-06-27T15:46:28+00:00 2022-06-27T15:46:28+00:00In: Error

The best guide for fixing ”mongoerror: failed to connect to server [localhost:27017] on first connect” error.

  • 3

. Advertisement .

..3..

. Advertisement .

..4..

Hello, everyone.

I’m very tired of the ”mongoerror: failed to connect to server [localhost:27017] on first connect” because I’ve been thinking for some days but still haven’t found any solutions for it.

I was running this program:

[email protected]:~/workspace/nodejs/mongodb$ mongo
MongoDB shell version v3.4.9
connecting to: mongodb://127.0.0.1:27017
2017-10-30T14:32:21.476+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2017-10-30T14:32:21.477+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
[email protected]/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed

Suddenly I got a warning message:

Mongoerror: failed to connect to server [localhost:27017] on first connect

I didn’t know the cause of this error. Does anyone have suggestions and share them with me? Thanks!

failed to connect to server
  • 1 1 Answer
  • 116 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    lyytutoria Expert
    2022-06-27T16:10:33+00:00Added an answer on June 27, 2022 at 4:10 pm

    Hi, Shanestrackejr! Don’t be stressful. I am here to help you!!!

    The cause:

    The server cannot connect to the MongoDB because your MongoDB Service is not started.

    Solution:

    To solve this error, you have to activate MongoDB Service. You can do as the following:

    sudo service mongod start

    At the time Service is started, the Mongo Shell is also activated:

    [email protected]:~/workspace/nodejs/mongodb$ mongo
    MongoDB shell version v3.4.9
    connecting to: mongodb://127.0.0.1:27017
    MongoDB server version: 3.4.9

    MongoDB records the URL in the terminal when Mongo Shell is launched, looks like the base of URL below:

    connecting to: mongodb://127.0.0.1:27017

    Finally, let’s check carefully whether you provide the similar base URL or the same Port and IP for your Node.js Application or not by doing:

    // URL at which MongoDB service is working
    var url = "mongodb://localhost:27017";
    
    // A Client to MongoDB
    var MongoClient = require('mongodb').MongoClient;
    
    // Connect to MongoDB Service
    MongoClient.connect(url, function(err, db) {
    if (err) throw err;
    console.log("Connected to MongoDB!");
    db.close();
    });
    • 3
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.