0

I apologize if this has somehow been answered. But, I have been stuck on this for awhile now to the point where I am losing hope in using a local server (MongoDB). I am also a person simply learning all of this, so please forgive me if I am asking a "noob" question.


Setup: MacOS using iTerm, using brew.


Problem:

Was able to use MongoDB fine when I was using the bash shell. No problems at all.


Issue:

macOS forced me to switch to zsh shell and now, I can't run it.

after running mongod

The error message shows that I do not have the directory /data/db. I saw that others had the same problem.


What I have already tried:

  • reinstalling brew
  • reinstalling MongoDB
  • mkdir -p /data/db
  • switching path to the said directory

None seem to work. In fact, when I try to make /data/db, it states that it is a read-only file as follows.

after running mkdir -p /data/db

Please help me :(

RobC
  • 22,977
  • 20
  • 73
  • 80
mikeduges
  • 1
  • 1
  • When I use mongo I put the data in a local folder to the project, which you can git ignore if you like. I like having projects encapsulated and not leaving ghost data around on my PC. Have you tried having a local data path? – Dominic Oct 14 '19 at 08:28
  • Thanks for the comment. I have seen posts about creating local data paths, but have not tried it. I have seen that they are "not good"? Is that not true? Also, I am assuming local data path as in "create a data folder in the project and link it"? I have no idea how I'd do that, but I can try. – mikeduges Oct 14 '19 at 08:35
  • You can do it like this: `mongod --dbpath=./localdata`. I only start a mongo instance during development, when the app is deployed I just connect to a running service so I can't see how it's bad practice. – Dominic Oct 14 '19 at 08:42
  • alright, I can run the above now with a localdata folder that I created. Is there anyway it defaults to that path while running *mongod*? or do I have to type in the whole thing (mongod --dbpath=./localdata) everytime? – mikeduges Oct 14 '19 at 08:59
  • I have it as a NPM package.json script with the arg so depends how you're running it. You could set an `alias` in the terminal but would only apply for you – Dominic Oct 14 '19 at 09:14
  • P.S. If you prefer the data in your home directory it should work too - `--dbpath ~/data/db`. I run it per project as an NPM script so localdata works for me – Dominic Oct 14 '19 at 09:17
  • 1
    Alright, for now, I will run it with the specified dbpath. Thanks so much for taking the time to enlighten me. I am excited to move forward with node. Thanks again! – mikeduges Oct 14 '19 at 09:40
  • Duplicate of https://stackoverflow.com/questions/58283257/mongodb-doesnt-work-on-latest-mac-os10-15 – kevinadi Oct 14 '19 at 22:47

0 Answers0