Newbie - Mongod not working

I am very new to coding, terminal and using mongodb. I have been taking a udemy course and got past the mongodb installation and setup just fine and out of no where after I barely started the next project I started getting these errors when starting mongod. I spent a week trying to figure it out until I just tried to remove mongodb completely off my computer and reinstall everything. I am pretty sure I failed at that because it still does not work. I do not understand the error messages or which ones are even errors. The console logs are really daunting to look at for me because I am so new. I got stuck on this about 2 months ago and I had to stop for awhile and I started working on it a couple days ago and I just am completely stuck here. Some people suggested taking free courses which I think is a good idea once I can get this working again.
I have tried to switch the port #, I tried to change the dbpath location and it still does not load up. Can someone help me?

Thanks!

Error says non existent dirpath
What is your OS?
Did you try to create /data/db as suggested
How did you start mongod after changing the dirpath?

You can always start your own mongod by giving different values like port,dbpath other than default values

mongod --port --dbpath --logpath --fork
Choose a dir where your mongod can read/write say your home directory

Mac Big Sur.
I tried changing the port and dbpath many times.
mongod --dbpath data/db
mongod --port 27018

data/db is not same as /data/db
One is a relative path and other one is absolute path
First command failed because it could not find dbpath directory
Second command failed as you did not specify dbapth so it looks for default dir /data/db which is not existing as you created it under some other dir
Before you start mongod cd to the each dir you mentioned in your command or config file

1 Like

I have cd into data/db and the folder pops up. I changed the config file under /usr/local/etc/mongod.conf to data/db as well. I imagine what ever am stuck on is probably super simple. I am so new and I spent weeks trying to figure this out but I am completely stuck. I really appreciate your help.

I repeat data/db is not same as /data/db
show me the output of cd /data/db
I need exact screenshot (not manually typed) of your terminal
In Mac Big Sur access to root folder is removed
So creating /data/db dir would have failed and you created it somewhere else
So give that absolute path.It will work

1 Like

if I cd /data/db
bash: cd: /data/db: No such file or directory

Yes i understood
Where did you create your data/db dir?
If you are confused with Unix dir structure give a simple dirpath

mongod --port 28000 --dbpath your_home_dir --logpath your_home_dir/mongod.log --fork
After mongod is up make sure to connect using your_port_number

mongo --port 28000

Hope it clarifies

1 Like

Hey @base_az,

Welcome to the MongoDB Community forum.!!

We hope that you were able to solve your Mongodb configuration issue.
We want to wish you all the best for your MongoDB learning Journey and all future endeavors.:sparkles:

In case of any help around MongoDB, please feel free to reach out to us. We and our super awesome community peers will be happy to help.!!

And, a big shout-out to @Ramachandra_Tummala for responding instantly and helping @base_az. :clap: We highly appreciate it.

Kind Regards,
Kushagra

I am sorry. I can’t emphasize enough how new I am. I am trying to google what you are saying because I don’t understand what the log path is or how to even search where it is. I vaguely know what forking is with git hub but I have no idea the context of how to use that now. I spent some time trying to figure out each of your messages before responding but I just don’t understand.

I just saved my data/db on the home directory (I think). So the if I open the folder it is my username folder. I have moved it around and used mongod --dbpath data/db to change the location.

Show the output of below commands

pwd
cd data/db
ls
All you have to do is give valid paths for dbpath and logpath parameters in your command

How did you start mongod in your first post?(i think it was just mongod)
You mentioned you changed dir from /data/db to something else
After changing this how did you try to start mongod again
mongod can be started in different ways with and without config file or from command line
So show us clearly what you attempted

pwd
/Users/myName
cd/ data/db
ls

I use mongod to boot it. and mongod --dbpath to change but I would use mongod after that. I am sorry, I am sure this is as frustrating for you as it is for me. I really do appreciate all your help. I am going to take some more entry level terminal and mongod classes once I can get it working again. Thank you.

hello, did you get a chance to check on my last reply? Thank you.

I just realized I didn’t reply to you in the other two messages, so you probably didn’t see them. :expressionless:

Yes i have seen your replies.Thought you are doing more research and would come back later :grinning:
Your snapshot clearly shows datafiles got created in that directory
May be your mongod came up and was terminated?
When you run mongod without --fork it runs in foreground and the session should be kept active
If you close or ctl+c it will get terminated
You have to open another session and connect to your mongod using mongo command

mongod is not used to boot the process.It is used to start mongod.If you want to bounce/boot this process you should shut it down gracefully by db.shutdown or kill

Have you tried what i suggested instead of getting confused with /data/db and data/db directories
Create a directory test under you /Users/yourname
Then start mongod as below
mongod --port 28000 --dbpath /Users/yourname/test --logpath /Users/yourname/test/mongod.log --fork
Once mongod is up connect using
mongo --port 28000

If you still insist on starting mongod on data/db
cd to /Users/yourname
mongod --dbpath /Users/yourname/data/db
Here we are assuming no other mongod running on port 27017
If it does not work clean the contents of your data/db dir and run the command again (take a backup if those files are important for you before cleaning)

I believe it is working with the test directory. Now that I am in I should do db.shutdown to close this instance and the possible other instance that might be left open from the last time I was in?
Thanks again for all your help :smiley:

It’s your wish
You can have multiple mongods running on your box
You can check by ps -ef|grep mongod

To shutdown current one
use admin
db.shutdownServer()

I doubt the first mongod which you started is still active as you did not use --fork.So it would have got terminated when you terminated/closed your session
Also look into your messages on your terminal about bindip and access control
You should secure your mongodb from unauthenticated access
Refer documentation for --auth and bindIp params and their usage

I have absolutely no idea what any of this means still. I don’t understand anything what you are saying either. I am hopeful with your help that I can get this running so I could do some tutorials so I can finally understand. I did one quick tutorial that was maybe 30 minutes long and on the 2nd tutorial everything broke. I spent the last 5 minutes googling how to check messages for bindip and access control with nothing but more confusion. I don’t know anything, I do appreciate all your help but I am way too much of a beginner to understand what you are saying. I know you are trying to help but I am very confused. I tried using the
ps -ef|grep mongod
And I got
uncaught exception: SyntaxError: unexpected token: identifier :
@(shell):1:12