Installing and Running MongoDB on OSX

前端 未结 10 1289
醉话见心
醉话见心 2020-12-02 05:21

If someone can provide some insights here I would GREATLY appreciate it.

I am new to MongoDB, and (relatively) new to the command line.

I had a express/nod

相关标签:
10条回答
  • 2020-12-02 05:55

    Nothing less likely to be outdated that the official docs: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

    0 讨论(0)
  • 2020-12-02 05:59

    Updated answer (9/2/2019):

    Homebrew has removed mongodb formula from its core repository, see this pull request.

    The new way to install mongodb using Homebrew is as follows:

    ~> brew tap mongodb/brew
    ~> brew install mongodb-community
    

    After installation you can start the mongodb service by following the caveats:

    ~> brew info mongodb-community
    mongodb/brew/mongodb-community: stable 4.2.0
    High-performance, schema-free, document-oriented database
    https://www.mongodb.com/
    Not installed
    From: https://github.com/mongodb/homebrew-brew/blob/master/Formula/mongodb-community.rb
    ==> Caveats
    To have launchd start mongodb/brew/mongodb-community now and restart at login:
      brew services start mongodb/brew/mongodb-community
    Or, if you don't want/need a background service you can just run:
      mongod --config /usr/local/etc/mongod.conf
    

    Deprecated answer (8/27/2019):

    I assume you are using Homebrew. You can see the additional information that you need using brew info $FORMULA

    ~> brew info mongo                                                           255
    mongodb: stable 2.4.6, devel 2.5.1
    http://www.mongodb.org/
    /usr/local/Cellar/mongodb/2.4.5-x86_64 (20 files, 287M) *
      Built from source
    From: https://github.com/mxcl/homebrew/commits/master/Library/Formula/mongodb.rb
    ==> Caveats
    To reload mongodb after an upgrade:
        launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
        launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
    

    Caveats is what you need to follow after installation.

    0 讨论(0)
  • 2020-12-02 06:00

    additionally you may want mongo to run on another port, then paste this command on terminal,

    mongod --dbpath /data/db/ --port 27018
    

    where 27018 is the port we want mongo to run on

    assumptions

    1. mongod exists in your bin i.e /usr/local/bin/ for mac ( which would be if you installed with brew), otherwise you'd need to navigate to the path where mongo is installed
    2. the folder /data/db/ exists
    0 讨论(0)
  • 2020-12-02 06:00

    Make sure you are logged in as root user in your terminal.

    Steps to start mongodb server in your mac

    1. Open Terminal
    2. Run the command sudo su
    3. Enter your administrator password
    4. run the command mongod
    5. MongoDb Server starts

    Hope it helps you. Thanks

    0 讨论(0)
  • 2020-12-02 06:05

    Assuming you have created the data/db directory under bin after install.

    1. Start a terminal for your mongo server
    2. Go to <mongodb-install-directory>/bin directory
    3. Run the command

      ./mongod

    4. Start a terminal for your mongo shell

    5. Go to <mongodb-install-directory>/bin directory
    6. Run the command (make sure you put the name of the database)

      ./mongo test

    0 讨论(0)
  • 2020-12-02 06:09

    If you have installed mongodb through homebrew then you can simply start mongodb through

    brew services start mongodb
    

    Then access the shell by

    mongo
    

    You can shut down your db by

    brew services stop mongodb
    

    You can restart your db by

    brew services restart mongodb
    

    For more options

    brew info mongodb
    
    0 讨论(0)
提交回复
热议问题