user4943236
user4943236

Reputation: 6344

mongodb: restart after removing lock file

I'm on OS/X Macbook and recently installed mongodb to try my hands on it. I installed it using shell commands. I scrapped some data and passed into it and when I tried looking for it, the connection was getting failed. On googling the root cause, I found there was some mongodb.lock file, and I removed it using bash command. Now, I'm trying to restart using the following command

sudo service mongodb restart

However, it is saying

sudo: service: command not found

in addition, if I start mongodb by navigating to folder and then using the command ./bin/mongo, it displays the following error:

MongoDB shell version: 3.0.7 connecting to: test 2015-11-08T14:47:56.965+0800 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused 2015-11-08T14:47:56.967+0800 E QUERY Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at connect (src/mongo/shell/mongo.js:179:14) at (connect):1:6 at src/mongo/shell/mongo.js:179 exception: connect failed

can someone please help how to resolve it.

Upvotes: 0

Views: 544

Answers (2)

Markus W Mahlberg
Markus W Mahlberg

Reputation: 20703

  1. Like Yuri wrote, there is no service command on OS X. You need to manage MongoDB yourself by starting it with the mongod command.
  2. An Alternative is to install MongoDB via MacPorts. After you successfully installed MacPorts, you simply install MongoDB with

    sudo port install mongodb
    

    You can start MongoDB quite easily then with

    sudo port load mongodb
    

    and stop it with

    sudo port unload mongodb
    
  3. mongo is the client. You haven't had the server running, so it is only natural that you can not connect to the server.

Some side note: OS X is not very close to Linux. OS X is based on a flavor of BSD-UNIX, which in turn is based on Research UNIX. Linux started as a free implementation of Minix, based on GNU utilities. So assuming that you'd have Linux tools available on the OS X command line is pretty dangerous. Often, the tools (if present) even share the name, but are different implementations of the same functionality with some differences in usage. So, get it in your head: With OS X, you do not use the hipster version of Linux – you use BSD on steroids. Hence, I will remove the "linux" tag and add the OS X tag.

Upvotes: 1

Yuri G.
Yuri G.

Reputation: 4648

AFAIK there is no service command on Mac. And ./bin/mongo runs a shell client, you need to run .bin/mongod with relevant --dbpath argument. You can find more info here

Upvotes: 1

Related Questions