此外你还可以使用 OSX 的 brew 来安装 mongodb: brew tap mongodb/brew brew install mongodb-community@4.4 @ 符号后面的 4.4 是最新版本号。 安装信息:.
MongoDB Atlasis a hosted MongoDB service option in the cloud which requires noinstallation overhead and offers a free tier to get started.
Use this tutorial to manually install MongoDB 4.4 CommunityEdition on macOS using a downloaded .tgz tarball.
This tutorial installs MongoDB 4.4 CommunityEdition. To install a different version of MongoDB Community,use the version drop-down menu in the upper-left corner of this page toselect the documentation for that version.
While MongoDB can be installed manually via a downloaded .tgztarball as described in this document, it is recommended to use thebrew package manager on your system to install MongoDB ifpossible. Using a package manager automatically installs all neededdependencies, provides an example mongod.conf file to get youstarted, and simplifies future upgrade and maintenance tasks.
➤ See Install MongoDB using the brew Package Managerfor instructions.
MongoDB 4.4 Community Edition supports macOS 10.13 or later.
See Supported Platforms for more information.
Before deploying MongoDB in a production environment, consider theProduction Notes document which offersperformance considerations and configuration recommendations forproduction MongoDB deployments.
Follow these steps to manually install MongoDB Community Edition fromthe .tgz.
Download the MongoDB Communitytgz tarball from the followinglink:
➤MongoDB Download Center
If your web browser automatically unzips the file as part of thedownload, the file would end in .tar instead.
PATH environment variable.¶The MongoDB binaries are in the bin/ directory of the tarball.You can either:
Copy the binaries into a directory listed in your PATHvariable, such as /usr/local/bin (Update/path/to/the/mongodb-directory/ with your installationdirectory as appropriate)
Create symbolic links to the binaries from a directory listed inyour PATH variable, such as /usr/local/bin (Update/path/to/the/mongodb-directory/ with your installationdirectory as appropriate):
ulimit Settings for the recommendedsettings for your platform.ulimit value for number of open files is under 64000.Follow these steps to run MongoDB Community Edition. These instructionsassume that you are using the default settings.
Before you start MongoDB for the first time, you must create thedirectory to which the mongod process will write data.
For example, to create the /usr/local/var/mongodb directory:
Starting with macOS 10.15 Catalina, Apple restricts access to theMongoDB default data directory of /data/db. On macOS 10.15Catalina, you must use a different data directory, such as/usr/local/var/mongodb.
You must also create the directory in which the mongod processwill write its log file:
For example, to create the /usr/local/var/log/mongodb directory:
Ensure that the user account running mongod has readand write permissions for these two directories. If you are runningmongod as your own user account, and you just createdthe two directories above, they should already accessible to youruser. Otherwise, you can use chown to set ownership,substituting the appropriate user:
To run MongoDB, run the mongod process at the systemprompt, providing the two parameters dbpath and logpathfrom above, and the fork parameter to run mongodin the background. Alternatively, you may choose to store the valuesfor dbpath, logpath, fork, and many other parameters in aconfiguration file.
mongod with command-line parameters¶Run the mongod process at the system prompt,providing the three necessary parameters directly on thecommand-line:
mongod with a configuration file¶Run the mongod process at the system prompt,providing the path to aconfiguration filewith the config parameter:
macOS may prevent mongod from running after installation. Ifyou receive a security error when starting mongodindicating that the developer could not be identified or verified,do the following to grant mongod access to run:
mongod, labelled either OpenAnyway or Allow Anyway depending on your version ofmacOS.Verify that MongoDB has started successfully:
If you do not see a mongod process running, check the logfile forany error messages.
Start a mongo shell on the same host machine as themongod. You can run the mongo shellwithout any command-line options to connect to amongod that is running on your localhost with thedefault port of 27017:
macOS may prevent the mongo shell from running after installation. Ifyou receive a security error when starting the mongo shellindicating that the developer could not be identified or verified,do the following to grant the mongo shell access to run:
mongo shell, labelled either OpenAnyway or Allow Anyway depending on your version ofmacOS.For more information on connecting using the mongoshell, such as to connect to a mongod instance runningon a different host and/or port, see The mongo Shell.
To help you start using MongoDB, MongoDB provides GettingStarted Guides in various driver editions. SeeGetting Started for the available editions.
By default, MongoDB launches with bindIp set to127.0.0.1, which binds to the localhost network interface. Thismeans that the mongod can only accept connections fromclients that are running on the same machine. Remote clients will not beable to connect to the mongod, and the mongod willnot be able to initialize a replica set unless this value is setto a valid network interface.
This value can be configured either:
bindIp, or--bind_ipBefore binding to a non-localhost (e.g. publicly accessible)IP address, ensure you have secured your cluster from unauthorizedaccess. For a complete list of security recommendations, seeSecurity Checklist. At minimum, considerenabling authentication andhardening network infrastructure.
For more information on configuring bindIp, seeIP Binding.
© MongoDB, Inc 2008-present. MongoDB, Mongo, and the leaf logo are registered trademarks of MongoDB, Inc.
MongoDB is a fully flexible index support and rich queries database. It is a NoSQL database. MongoDB 4.0 supports multi-document ACID transactions. This tutorial will help you to install MongoDB database server on macOS. After the installation, you may also like our MongoDB tutorial.
First of all, update the Homebrew package repository index. Then install MongoDB using homebrew installer. This will install MongoDB at location /usr/local/Cellar/mongodb.
Start MongoDB – Use the following command to start MongoDB from a terminal. Make sure to change 4.0.3_1 in below command with the installed version of MongoDB on your macOS.
Stop MongoDB – Simply use the unload options to stop running MongoDB database service on macOS.
After starting MongoDB service, just type “mongo” on the terminal. This will connect to MongoDB service running on the local system.
You can visit our MongoDB tutorial section to read and understand working with MongoDB.