- How to install MongoDB on macOS using Homebrew
- Creating Data Folder Before you install and use MongoDB, you need to create a data/db folder on your computer for storing MongoDB data. Before macOS Catalina, you can create this folder in the user’s root directory with the following command: If you are on macOS Catalina or Big Sur (or any future release), you can not use the root folder for this purpose. macOS Catalina runs in a read-only system volume, separate from other files on the system. Apple created a secondary volume on Catalina that you need to use for storing MongoDB data folder: Installing MongoDB You can install the MongoDB community edition with Homebrew. If Homebrew is not already installed, execute the following command first: Now update Homebrew to the latest version: Next, tap the MongoDB formulae into Homebrew: Finally, execute the following command to install the MongoDB community edition: That’s it. MongoDB is now installed on your macOS computer. Managing MongoDB Service To manage MongoDB on your macOS computer, you can use the brew services command. First of all, install brew services by tapping homebrew/services : To start the MongoDB service, you use the following command: The above command will start MongoDB as a background service. Here’s what you will see on the terminal: Note: You can also use the run command instead of start . The start command will configure MongoDB to automatically start when you log into your Macbook. If you do not want to run MongoDB all the time, use the run command instead. To check the current status of the MongoDB service, issue the following command: The above command will output something like below: You can stop the service anytime by typing: If you want to restart the service, use the following command: Creating Aliases To make your life easier, you can also create aliases for managing MongoDB service. Just add the following to Next source the /.zshrc file to load aliases: Now you can use aliases to manage your MongoDB service: Conclusion That’s all folks for today. In this article, we learned how to install the MongoDB community edition on macOS Catalina and higher. We use the Homebrew package manager to install MongoDB binaries and to manage MongoDB service. If you enjoy reading this article, don’t forget to share it with your friends and followers. ✌️ Like this article? Follow me on Twitter and LinkedIn. You can also subscribe to RSS Feed. Источник Install MongoDB Community Edition on macOSВ¶ MongoDB Atlas is a hosted MongoDB service option in the cloud which requires no installation overhead and offers a free tier to get started. OverviewВ¶ Use this tutorial to install MongoDB 5.0 Community Edition on macOS using the third-party Homebrew package manager. Starting with MongoDB 4.4.1, installing MongoDB via Homebrew also installs the MongoDB Database Tools. See Using the MongoDB Database Tools for more information. MongoDB VersionВ¶ This tutorial installs MongoDB 5.0 Community Edition. To install a different version of MongoDB Community , use the version drop-down menu in the upper-left corner of this page to select the documentation for that version. ConsiderationsВ¶ Platform SupportВ¶ MongoDB 5.0 Community Edition removes support for macOS 10.13 MongoDB 5.0 Community Edition supports macOS 10.14 or later. See Supported Platforms for more information. Production NotesВ¶ Before deploying MongoDB in a production environment, consider the Production Notes document which offers performance considerations and configuration recommendations for production MongoDB deployments. Install MongoDB Community EditionВ¶ PrerequisitesВ¶ Ensure your system meets each of the following prerequisites. You only need to perform each prerequisite step once on your system. If you have already performed the prerequisite steps as part of an earlier MongoDB installation using Homebrew, you can skip to the installation procedure. Install Xcode Command-Line ToolsВ¶ Homebrew requires the Xcode command-line tools from Apple’s Xcode. Install the Xcode command-line tools by running the following command in your macOS Terminal: Install HomebrewВ¶ macOS does not include the Homebrew brew package by default. Installing MongoDB 5.0 Community EditionВ¶ Follow these steps to install MongoDB Community Edition using Homebrew’s brew package manager. Be sure that you have followed the installation prerequisites above before proceeding. Tap the MongoDB Homebrew Tap to download the official Homebrew formula for MongoDB and the Database Tools, by running the following command in your macOS Terminal: If you have already done this for a previous installation of MongoDB, you can skip this step. To install MongoDB, run the following command in your macOS Terminal application: Alternatively, you can specify a previous version of MongoDB if desired. You can also maintain multiple versions of MongoDB side by side in this manner. If you have previously installed an older version of the formula, you may encounter a ChecksumMismatchError. To resolve, see Troubleshooting ChecksumMismatchError. The installation includes the following binaries: The mongod server The mongos sharded cluster query router The MongoDB Shell, mongosh In addition, the installation creates the following files and directories at the location specified below, depending on your Apple hardware: See Apple’s documentation for the current list of Apple hardware using the M1 processor. You can also run the following command to check where brew has installed these files and directories: Starting with MongoDB 4.4.1, the installation also includes the MongoDB Database Tools. See Using the MongoDB Database Tools for more information. Run MongoDB Community EditionВ¶ Follow these steps to run MongoDB Community Edition. These instructions assume that you are using the default settings. You can run MongoDB as a macOS service using brew , or you can run MongoDB manually as a background process. It is recommended to run MongoDB as a macOS service, as doing so sets the correct system ulimit values automatically (see ulimit settings for more information). To run MongoDB (i.e. the mongod process) as a macOS service, run: To stop a mongod running as a macOS service, use the following command as needed: To run MongoDB (i.e. the mongod process) manually as a background process, run: For macOS running Intel processors: To stop a mongod running as a background process, connect to the mongod using mongosh, and issue the shutdown command as needed. Both methods use the mongod.conf file created during the install. You can add your own MongoDB configuration options to this file as well. macOS may prevent mongod from running after installation. If you receive a security error when starting mongod indicating that the developer could not be identified or verified, do the following to grant mongod access to run: Open System Preferences Select the Security and Privacy pane. Under the General tab, click the button to the right of the message about mongod , labelled either Open Anyway or Allow Anyway depending on your version of macOS. To verify that MongoDB is running, perform one of the following: If you started MongoDB as a macOS service: You should see the service mongodb-community listed as started . If you started MongoDB manually as a background process: You should see your mongod process in the output. You can also view the log file to see the current status of your mongod process: /usr/local/var/log/mongodb/mongo.log . Connect and Use MongoDBВ¶ To begin using MongoDB, connect mongosh to the running instance. From a new terminal, issue the following: macOS may prevent mongosh from running after installation. If you receive a security error when starting mongosh indicating that the developer could not be identified or verified, do the following to grant mongosh access to run: Open System Preferences Select the Security and Privacy pane. Under the General tab, click the button to the right of the message about mongosh , labelled either Open Anyway or Allow Anyway depending on your version of macOS. For information on CRUD (Create,Read,Update,Delete) operations, see: Using the MongoDB Database ToolsВ¶ Starting in MongoDB 4.4.1, installing MongoDB via brew also installs the MongoDB Database Tools. The MongoDB Database Tools are a collection of command-line utilities for working with a MongoDB deployment, including data backup and import/export tools like mongoimport and mongodump as well as monitoring tools like mongotop . Once you have installed the MongoDB Server in the steps above, the Database Tools are available directly from the command line in your macOS Terminal application. For example you could run mongotop against your running MongoDB instance by invoking it in your macOS Terminal like so: It should start up, connect to your running mongod , and start reporting usage statistics. See the MongoDB Database Tools Documentation for usage information for each of the Database Tools. Additional InformationВ¶ Localhost Binding by DefaultВ¶ By default, MongoDB launches with bindIp set to 127.0.0.1 , which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod , and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface. This value can be configured either: in the MongoDB configuration file with bindIp , or via the command-line argument —bind_ip Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist. At minimum, consider enabling authentication and hardening network infrastructure. For more information on configuring bindIp , see IP Binding. Troubleshooting ChecksumMismatchErrorВ¶ If you have previously installed an older version of the formula, you may encounter a ChecksumMismatchError resembling the following: Remove the downloaded .tgz archive. Источник How do I restart mongodb? I installed mongoldb using the one-click installer. I changed the config bind-ip and commented it out (to allow it to accept any connection). Then I wanted to restart to make the changes take effect, so I did the following: Then I expected it to try and reconnect, however this happened: How can I restart my mongod process? Related Join 1M+ other developers and: Get help and share knowledge in Q&A Subscribe to topics of interest Get courses & tools that help you grow as a developer or small business owner Join Now Hello Guys, I installed mongodb in my ubuntu 15.10. When I run mongo comment gotting below error $ mongo MongoDB shell version: 2.6.10 connecting to: test 2016-07-02T11:12:17.792+0530 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused 2016-07-02T11:12:17.794+0530 Error: couldn’t connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146 exception: connect failed Please provide solution. When I run rockmongo I got the below error Unable to connect MongoDB, please check your configurations. MongoDB said:Failed to connect to: 127.0.0.1:27017: Previous connection attempts failed, server blacklisted. Unable to connect MongoDB, please check your configurations. MongoDB said:Failed to connect to: 127.0.0.1:27017: Connection refused. Please answer me as soon as possible. These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others. You can start MongoDB by running the following command as root: Thanks, this worked perfectly 🙂 HI @neiljny, after changing the config bind-ip and commented it out, I could connect to the server ip with port 27017 but the authorization failed using the username (root) and server password (which I use to SSH connect via terminal). I don’t know where I’m wrong. I use Robomongo btw Related question Droplet App MongoDB String I can´t connect externally from a Droplet with a MongoDB from Marketplace. I can enter with SSH but it´s impossible to enter with user and password. I generated the user and password properly, and I can´t connect externally. «` . question GUI for MongoDB needed to mange Meteor app Yo, Deploying a MeteorJS app, thus using MongoDB for the database. How do we use a GUI to manage the database? I tried using RoboMongo and MongoChef but neither works. Anyone with Meteor apps managing their collections with a GUI? . question Confirmation email from WordPress wp-admin password change never arrives Hi all, Using a linux out-of-the-box wordpress install droplet here: 45.55.230.208 I’ve setup scaleanalytics.com to point to it via the droplet dns administration. I’ve also added the Google MX there (used to have gmail mx via godaddy). . question Digital Occean Cloud server has user interface logging ? Digital Occean Cloud server has user interface logging and install application ? Источник 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 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. 2 Answers 2 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 Like Yuri wrote, there is no service command on OS X. You need to manage MongoDB yourself by starting it with the mongod command. An Alternative is to install MongoDB via MacPorts. After you successfully installed MacPorts, you simply install MongoDB with You can start MongoDB quite easily then with and stop it with 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. Источник
- Installing MongoDB
- Managing MongoDB Service
- Creating Aliases
- Conclusion
- Install MongoDB Community Edition on macOSВ¶
- OverviewВ¶
- MongoDB VersionВ¶
- ConsiderationsВ¶
- Platform SupportВ¶
- Production NotesВ¶
- Install MongoDB Community EditionВ¶
- PrerequisitesВ¶
- Install Xcode Command-Line ToolsВ¶
- Install HomebrewВ¶
- Installing MongoDB 5.0 Community EditionВ¶
- Run MongoDB Community EditionВ¶
- Connect and Use MongoDBВ¶
- Using the MongoDB Database ToolsВ¶
- Additional InformationВ¶
- Localhost Binding by DefaultВ¶
- Troubleshooting ChecksumMismatchErrorВ¶
- How do I restart mongodb?
- Related
- Related
- mongodb: restart after removing lock file
- 2 Answers 2
How to install MongoDB on macOS using Homebrew
December 06, 2020 • Atta
In an earlier article, I wrote about how to install the MongoDB community edition on Ubuntu operating system. Today, you’ll learn to install the MongoDB community edition on macOS Catalina and higher.
Creating Data Folder
Before you install and use MongoDB, you need to create a data/db folder on your computer for storing MongoDB data.
Before macOS Catalina, you can create this folder in the user’s root directory with the following command:
If you are on macOS Catalina or Big Sur (or any future release), you can not use the root folder for this purpose. macOS Catalina runs in a read-only system volume, separate from other files on the system.
Apple created a secondary volume on Catalina that you need to use for storing MongoDB data folder:
Installing MongoDB
You can install the MongoDB community edition with Homebrew. If Homebrew is not already installed, execute the following command first:
Now update Homebrew to the latest version:
Next, tap the MongoDB formulae into Homebrew:
Finally, execute the following command to install the MongoDB community edition:
That’s it. MongoDB is now installed on your macOS computer.
Managing MongoDB Service
To manage MongoDB on your macOS computer, you can use the brew services command.
First of all, install brew services by tapping homebrew/services :
To start the MongoDB service, you use the following command:
The above command will start MongoDB as a background service. Here’s what you will see on the terminal:
Note: You can also use the run command instead of start . The start command will configure MongoDB to automatically start when you log into your Macbook. If you do not want to run MongoDB all the time, use the run command instead.
To check the current status of the MongoDB service, issue the following command:
The above command will output something like below:
You can stop the service anytime by typing:
If you want to restart the service, use the following command:
Creating Aliases
To make your life easier, you can also create aliases for managing MongoDB service. Just add the following to
Next source the
/.zshrc file to load aliases:
Now you can use aliases to manage your MongoDB service:
Conclusion
That’s all folks for today. In this article, we learned how to install the MongoDB community edition on macOS Catalina and higher.
We use the Homebrew package manager to install MongoDB binaries and to manage MongoDB service.
If you enjoy reading this article, don’t forget to share it with your friends and followers.
✌️ Like this article? Follow me on Twitter and LinkedIn. You can also subscribe to RSS Feed.
Источник
Install MongoDB Community Edition on macOSВ¶
MongoDB Atlas is a hosted MongoDB service option in the cloud which requires no installation overhead and offers a free tier to get started.
OverviewВ¶
Use this tutorial to install MongoDB 5.0 Community Edition on macOS using the third-party Homebrew package manager.
Starting with MongoDB 4.4.1, installing MongoDB via Homebrew also installs the MongoDB Database Tools. See Using the MongoDB Database Tools for more information.
MongoDB VersionВ¶
This tutorial installs MongoDB 5.0 Community Edition. To install a different version of MongoDB Community , use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.
ConsiderationsВ¶
Platform SupportВ¶
- MongoDB 5.0 Community Edition removes support for macOS 10.13
MongoDB 5.0 Community Edition supports macOS 10.14 or later.
See Supported Platforms for more information.
Production NotesВ¶
Before deploying MongoDB in a production environment, consider the Production Notes document which offers performance considerations and configuration recommendations for production MongoDB deployments.
Install MongoDB Community EditionВ¶
PrerequisitesВ¶
Ensure your system meets each of the following prerequisites. You only need to perform each prerequisite step once on your system. If you have already performed the prerequisite steps as part of an earlier MongoDB installation using Homebrew, you can skip to the installation procedure.
Install Xcode Command-Line ToolsВ¶
Homebrew requires the Xcode command-line tools from Apple’s Xcode.
Install the Xcode command-line tools by running the following command in your macOS Terminal:
Install HomebrewВ¶
macOS does not include the Homebrew brew package by default.
Installing MongoDB 5.0 Community EditionВ¶
Follow these steps to install MongoDB Community Edition using Homebrew’s brew package manager. Be sure that you have followed the installation prerequisites above before proceeding.
Tap the MongoDB Homebrew Tap to download the official Homebrew formula for MongoDB and the Database Tools, by running the following command in your macOS Terminal:
If you have already done this for a previous installation of MongoDB, you can skip this step.
To install MongoDB, run the following command in your macOS Terminal application:
Alternatively, you can specify a previous version of MongoDB if desired. You can also maintain multiple versions of MongoDB side by side in this manner.
If you have previously installed an older version of the formula, you may encounter a ChecksumMismatchError. To resolve, see Troubleshooting ChecksumMismatchError.
The installation includes the following binaries:
- The mongod server
- The mongos sharded cluster query router
- The MongoDB Shell, mongosh
In addition, the installation creates the following files and directories at the location specified below, depending on your Apple hardware:
See Apple’s documentation for the current list of Apple hardware using the M1 processor. You can also run the following command to check where brew has installed these files and directories:
Starting with MongoDB 4.4.1, the installation also includes the MongoDB Database Tools. See Using the MongoDB Database Tools for more information.
Run MongoDB Community EditionВ¶
Follow these steps to run MongoDB Community Edition. These instructions assume that you are using the default settings.
You can run MongoDB as a macOS service using brew , or you can run MongoDB manually as a background process. It is recommended to run MongoDB as a macOS service, as doing so sets the correct system ulimit values automatically (see ulimit settings for more information).
To run MongoDB (i.e. the mongod process) as a macOS service, run:
To stop a mongod running as a macOS service, use the following command as needed:
To run MongoDB (i.e. the mongod process) manually as a background process, run:
For macOS running Intel processors:
To stop a mongod running as a background process, connect to the mongod using mongosh, and issue the shutdown command as needed.
Both methods use the mongod.conf file created during the install. You can add your own MongoDB configuration options to this file as well.
macOS may prevent mongod from running after installation. If you receive a security error when starting mongod indicating that the developer could not be identified or verified, do the following to grant mongod access to run:
- Open System Preferences
- Select the Security and Privacy pane.
- Under the General tab, click the button to the right of the message about mongod , labelled either Open Anyway or Allow Anyway depending on your version of macOS.
To verify that MongoDB is running, perform one of the following:
If you started MongoDB as a macOS service:
You should see the service mongodb-community listed as started .
If you started MongoDB manually as a background process:
You should see your mongod process in the output.
You can also view the log file to see the current status of your mongod process: /usr/local/var/log/mongodb/mongo.log .
Connect and Use MongoDBВ¶
To begin using MongoDB, connect mongosh to the running instance. From a new terminal, issue the following:
macOS may prevent mongosh from running after installation. If you receive a security error when starting mongosh indicating that the developer could not be identified or verified, do the following to grant mongosh access to run:
- Open System Preferences
- Select the Security and Privacy pane.
- Under the General tab, click the button to the right of the message about mongosh , labelled either Open Anyway or Allow Anyway depending on your version of macOS.
For information on CRUD (Create,Read,Update,Delete) operations, see:
Using the MongoDB Database ToolsВ¶
Starting in MongoDB 4.4.1, installing MongoDB via brew also installs the MongoDB Database Tools.
The MongoDB Database Tools are a collection of command-line utilities for working with a MongoDB deployment, including data backup and import/export tools like mongoimport and mongodump as well as monitoring tools like mongotop .
Once you have installed the MongoDB Server in the steps above, the Database Tools are available directly from the command line in your macOS Terminal application. For example you could run mongotop against your running MongoDB instance by invoking it in your macOS Terminal like so:
It should start up, connect to your running mongod , and start reporting usage statistics.
See the MongoDB Database Tools Documentation for usage information for each of the Database Tools.
Additional InformationВ¶
Localhost Binding by DefaultВ¶
By default, MongoDB launches with bindIp set to 127.0.0.1 , which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod , and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.
This value can be configured either:
- in the MongoDB configuration file with bindIp , or
- via the command-line argument —bind_ip
Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist. At minimum, consider enabling authentication and hardening network infrastructure.
For more information on configuring bindIp , see IP Binding.
Troubleshooting ChecksumMismatchErrorВ¶
If you have previously installed an older version of the formula, you may encounter a ChecksumMismatchError resembling the following:
- Remove the downloaded .tgz archive.
Источник
How do I restart mongodb?
I installed mongoldb using the one-click installer. I changed the config bind-ip and commented it out (to allow it to accept any connection). Then I wanted to restart to make the changes take effect, so I did the following:
Then I expected it to try and reconnect, however this happened:
How can I restart my mongod process?
Related
Join 1M+ other developers and:
- Get help and share knowledge in Q&A
- Subscribe to topics of interest
- Get courses & tools that help you grow as a developer or small business owner
Join Now
Hello Guys, I installed mongodb in my ubuntu 15.10. When I run mongo comment gotting below error
$ mongo
MongoDB shell version: 2.6.10
connecting to: test
2016-07-02T11:12:17.792+0530 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-07-02T11:12:17.794+0530 Error: couldn’t connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
Please provide solution. When I run rockmongo I got the below error
Unable to connect MongoDB, please check your configurations. MongoDB said:Failed to connect to: 127.0.0.1:27017: Previous connection attempts failed, server blacklisted.
Unable to connect MongoDB, please check your configurations. MongoDB said:Failed to connect to: 127.0.0.1:27017: Connection refused.
Please answer me as soon as possible.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
You can start MongoDB by running the following command as root:
Thanks, this worked perfectly 🙂
HI @neiljny, after changing the config bind-ip and commented it out, I could connect to the server ip with port 27017 but the authorization failed using the username (root) and server password (which I use to SSH connect via terminal). I don’t know where I’m wrong. I use Robomongo btw
Related
question
Droplet App MongoDB String
I can´t connect externally from a Droplet with a MongoDB from Marketplace. I can enter with SSH but it´s impossible to enter with user and password. I generated the user and password properly, and I can´t connect externally. «` .
question
GUI for MongoDB needed to mange Meteor app
Yo, Deploying a MeteorJS app, thus using MongoDB for the database. How do we use a GUI to manage the database? I tried using RoboMongo and MongoChef but neither works. Anyone with Meteor apps managing their collections with a GUI? .
question
Confirmation email from WordPress wp-admin password change never arrives
Hi all, Using a linux out-of-the-box wordpress install droplet here: 45.55.230.208 I’ve setup scaleanalytics.com to point to it via the droplet dns administration. I’ve also added the Google MX there (used to have gmail mx via godaddy). .
question
Digital Occean Cloud server has user interface logging ?
Digital Occean Cloud server has user interface logging and install application ?
Источник
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
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.
2 Answers 2
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
- Like Yuri wrote, there is no service command on OS X. You need to manage MongoDB yourself by starting it with the mongod command.
An Alternative is to install MongoDB via MacPorts. After you successfully installed MacPorts, you simply install MongoDB with
You can start MongoDB quite easily then with
and stop it with
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.
Источник