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.

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

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 241179
Next
Alex Hales
  • 0
Alex HalesTeacher
Asked: August 10, 20222022-08-10T01:43:27+00:00 2022-08-10T01:43:27+00:00In: Linux, MongoDB, Ubuntu

linux – couldn’t connect to server 127.0.0.1 shell/mongo.js

  • 0

[ad_1]

It could be combination of $PATH and Permission issue.

Try following steps given below:

Update your $PATH variable to point to your MongoDB bin file. In my case brew install MongoDB to this folder:

/usr/local/Cellar/mongodb/2.4.6/

In order to update your $PATH variable, do following:

$ sudo vi /etc/paths

Then, press ‘i’ to insert text in Vi and append the your MongoDB path to the end of the ‘paths’ file and restart the terminal.

/usr/local/Cellar/mongodb/2.4.6/bin

Use ‘Esc : w q’ to save and exit from Vi editor.

Use echo to display your path variable:

$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/Cellar/mongodb/2.4.6/bin

Now try to check the Mongo version, if you get following, then you are on the right track!

$ mongo --version
MongoDB shell version: 2.4.6

Now we need to create the database directory. I used the default ‘/data/db’ location suggested in MongoDB docs. I also created a log directory to avoid any permission issues while Mongo tries to create any logs. Change ownership and that will do the job.

$ sudo mkdir /data/db
$ sudo mkdir /data/log
$ whoami
username
$ chown -R username /data

Now, we will create a default config file for MongoDB to be provided for the first time we run ‘mongod’ command. Now, I will also like to point out that ‘mongod’ will start a service, which will listen for incoming data connections. This is similar having ‘$service mysqld start’ executed.Let’s go ahead and create the config file. Please keep in mind that I have created very basic config file. However, you can add many other variables to configure MongoDB. This is the first time I am playing with MongoDB, so I just know as much as I read on MongoDB docs!I created ‘mongodb.conf’.

$ sudo vi /etc/mongodb.conf

Add following:

fork = true
port = 27017
quiet = true
dbpath = /data/db
logpath = /data/log/mongod.log
logappend = true
journal = true

Please note that the default port for MongoDB server is 27017. Use your own path for dbpath and logpath you created in Step – 5. Don’t forget to close and save the conf file.

Now we are all set to start our MongoDB service. Open two instances of Terminal.In Terminal 1, type in:

$ sudo mongod -f /etc/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 3516
all output going to: /data/log/mongod.log
child process started successfully, parent exiting

If you get above message, then know that you have successfully started your Mongod service.

Now, to connect to it, in Terminal 2 type following:

$mongo test
MongoDB shell version: 2.4.6
connecting to: test
Server has startup warnings:
Tue Sep 3 16:55:43.527 [initandlisten]
Tue Sep 3 16:55:43.527 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
>

Ignore the warnings, but you are successfully connected to the ‘test’ database! Cool!

That’s all. I applied this solution, when I tried to install copy of MongoDB on my Mac for the first time. See if this help you too.

For detailed post you can go here – http://arcanebytes.com/2013/09/03/mongodb-installation-on-mac-os-x/#comment-1036112094.

I hope it helps!

Cheers,
Chinmay

[ad_2]

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 401 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 371 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 367 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. 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.