How to start a mongodb service on mac OS X?

前端 未结 10 2036
一整个雨季
一整个雨季 2021-01-31 03:02

I have already installed Mongodb on my mac but the process is currently not running. How do I start the Mongodb service so that I can start using the commands?

相关标签:
10条回答
  • 2021-01-31 03:34

    As now is 2021 year, so start mongodb on Mac:

    Use brew

    • brew services start mongodb-community
      • for installed by: brew install mongodb-community

    similarly:

    for specify version

    • brew services start mongodb-community@4.2
      • for installed by: brew services install mongodb-community@4.2

    only running not want bootable

    the start means start and enable start at launch/boot

    for only run currently, use run:

    • brew services run mongodb-community

    check status

    after start, check status use:

    • brew services

    Manually

    for old version mongodb, the command is mongod:

    • Directly run: mongodb
    • Run with config: mongod --config /usr/local/etc/mongod.conf
      • the default config file path is: /usr/local/etc/mongod.conf
    • Run with only pass some parameter:
      • with database path: mongod --dbpath /data
        • /data is common mongodb database path
    0 讨论(0)
  • 2021-01-31 03:40

    Install and Run MongoDB with Homebrew

    Open the Terminal app and type

    brew update

    After updating Homebrew

    brew install mongodb-community@4.0

    After downloading Mongo, create the “db” directory. This is where the Mongo data files will live. You can create the directory in the default location by running

    sudo mkdir -p /data/db

    Make sure that the /data/db directory has the right permissions by running

    sudo chown -R id -un /data/db

    Run the Mongo daemon, in one of your terminal windows run

    brew services start mongodb-community

    This should start the Mongo server. Run the Mongo shell, with the Mongo daemon running in one terminal, type mongo in another terminal window. This will run the Mongo shell which is an application to access data in MongoDB. To exit the Mongo shell run quit() To stop the Mongo daemon hit ctrl-c

    start service:

    brew services start mongo

    https://treehouse.github.io/installation-guides/mac/mongo-mac.html

    0 讨论(0)
  • 2021-01-31 03:40

    Use this line it will fix the issue.

    Execute this line in your terminal at the mongo bin path:

    export PATH=<mongodb-install-directory>/bin:$PATH
    

    <mongodb-install-directory> replace this with your path, for example:

    export PATH=/Application/Mongo/bin:$PATH
    
    0 讨论(0)
  • 2021-01-31 03:41

    If you used homebrew to install MongoDB on macOS you type the following in terminal. Should do the trick in most cases.

    $ brew services start mongodb
    
    0 讨论(0)
提交回复
热议问题