Installing and Running MongoDB on OSX

前端 未结 10 1290
醉话见心
醉话见心 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 06:10

    Problem here is you are trying to open a mongo shell without starting a mongo db which is listening to port 127.0.0.1:27017(deafault for mongo db) thats what the error is all about:

    Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145 exception: connect failed
    

    The easiest solution is to open the terminal and type

    $ mongod --dbpath ~/data/db
    

    Note: dbpath here is "Users/user" where data/db directories are created

    i.e., you need to create directory data and sub directory db in your user folder. For e.g say `

    /Users/johnny/data

    After mongo db is up. Open another terminal in new window and type

    $ mongo
    

    it will open mongo shell with your mongo db connection opened in another terminal.

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

    Mac Installation:

    1. Install brew

      ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
      
    2. Update and verify you are good with

      brew update
      brew doctor
      
    3. Install mongodb with

      brew install mongodb
      
    4. Create folder for mongo data files:

      mkdir -p /data/db
      
    5. Set permissions

      sudo chown -R `id -un` /data/db
      
    6. Open another terminal window & run and keep running a mongo server/daemon

      mongod
      
    7. Return to previous terminal and run a mongodb shell to access data

      mongo
      

    To quit each of these later:

    1. The Shell:

      quit()
      
    2. The Server

      ctrl-c
      
    0 讨论(0)
  • 2020-12-02 06:18
    mongo => mongo-db console
    mongodb => mongo-db server
    

    If you're on Mac and looking for a easier way to start/stop your mongo-db server, then MongoDB Preference Pane is something that you should look into. With it, you start/stop your mongo-db instance via UI. Hope it helps!

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

    For those that could be facing the same problem and the solutions suggested above aren't working, for example in my case, I had installed mongodb-community, so you might wanna run the command below to restart your mongo server.

    For those that installed mongodb-community using brew

    brew services start mongodb-community

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