You would have to look into the log file for MongoDB to figure out what the issue is.
To find the log file run cat ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community@4.4.plist
. This will show you how brew
runs the service. In the results you should see something similar to the following:
This shows the config file that the mongod
process will use. You will want to look at the contents of that file ( cat /usr/local/etc/mongod.conf
) if your’s matches what I have. The config file will have a path for systemlog.path
which you can look at to see the error.
Without the log file messages we can’t tell you why MongoDB is not running. I will note that it’s interesting that root
is showing as the user for the service. This should be showing up as your normal user. You should never (well almost never) run a process as the root
user. Bad things can happen when you do.
I installed it using homebrew so it created folder as /opt/homebrew but not as usr/local so what should I do now??
Should I go with this
opt/homebrew/etc/mongod.conf
It doesn’t matter where brew
put it as long as the file exists. You would need to provide the info from the log file for us to be able to help you out. The steps I gave above will be able to get the log data, you just need to replace the paths that I listed from my machine with the paths that you get at each step from your machine.
Sure sir I will provide you with the details asap
I found a screenshot in a post you deleted that might shed some light on things. Below is a portion of that screenshot:
Note that it there are warnings stating that mongodb-community
must be run as non-root to start at user login. This would line up with what I said earlier that this should be your normal user. It looks like you need to brew uninstall
the package and manually clean up the mentioned directories and then brew install
with your normal user.
@Doug_Duncan sir see I made the changes is these correct? so that we can move further with the process
That could be correct for Redis, but I’m not sure. Redis processes have nothing to do with MongoDB.
Does brew services
still show root
as the user? If so you need to uninstall MongoDB and manually remove the directories/files in the screenshot that I posted earlier. You then need to reinstall MongoDB with your normal user account so that it can start up properly.
@Doug_Duncan sir as per you instruction i uninstalled mongodb and then manually removed the files and then reinstalled it as below
Unfortunately you have not supplied the MongoDB logs so again we can’t help with why the service is having issues starting up. I have put steps to get the log data in my original post. Once you post the log then we can provide more help.
@Doug_Duncan sir please check the mongo.log
Looking at the screenshot you provided I can see (about half way down) where it says Waiting for connections
and then towards the bottom of the screen I can see a connection was made with the MongoDB Shell.
Are you have issues?
Actually the first issue is in brew services it’s stating error with mongoDB community@5.0
And the second is temporary the connections are made through mongo shell and later it’s not able to connect to the server
If brew services start mongodb-community
is failing to start it sounds like there is an instance of mongod
already running, but that’s just a suggestion from what I’ve seen in the past. Again, the screenshot only shows a limited amount of the log file and from what I can see the mongod
service is indeed running.
What are the results of running ps -ef | grep mongod
? If you get a result then kill the process, delete the current log file and try staring via brew
once more. If mongod
fails to start the log should be relatively small. and it will be easier to see what’s happening.
OK, so this shows that mongod
is running and explains why you can connect via either mongo
or mongosh
. It also explains why you are not able to start the process using brew start ...
.
The 0 in the first column of the first line show that is running under the root
user which is not good. I would run kill 334
to stop that process and then brew service start mongodb-community
to allow brew
to run the process.
One thing to note here is that since the process is currently running as root
, that user probably owns the directories and files and those will need to be either deleted or have their ownership changed to your normal user so brew start ...
does not fail due to permission issues.
I can’t stress this enough, you should never run a service/daemon as the root
user unless explicitly told to do so, and even then only do it as long as you understand the risks involved with doing so.
@Doug_Duncan sir I did same as you said and getting this
Did you check permissions/ownership of dbpath & logpath directories as Doug_Duncan mentioned above?
Since it was run as root previously they might be owned by root and when you start the service as normal user mongod is not able to write
Your log shows only shutdown related messages none related to startup
Please show full path by pwd command
Did you try restart of your service
Also can you spinup another mongod on different port,dbpath,logpath where mongod can write
From command line
mongod --port 29000 --dbpath your_homedir --logpath your_homedir/mongod.log --fork
If it comes up connect by issuing
mongo --port 29000
Please refer to mongo documentation for various command line params
Ok sir let me try and get back to you
@Doug_Duncan sir or @Ramachandra_Tummala sir
kindly refer to this screenshot
This means your mognod
process is running and you have successfully connected to it.
Enabling authentication will get rid of the first message.
The second message is informational and I believe that the next time that you connect that message will not show.
The third message just states that you have the mongorc.js
file which was created by the older mongo
tool. As the note states, you can rename that file to mongosh.js
and then that message should go away as well.
Really all of these are just informational messages, although on a production system you will want to enable authentication, but on a test system running on your local machine that will no access to the outside and will not be holding sensitive data, leaving authentication turned off is fine.
From what I can see you have a fully functioning system now. Congratulations!
Thank you, sir, for your help and support if in the future I face any problem I can come back to you right?
Thank you @Doug_Duncan sir and @Ramachandra_Tummala sir
Definitely come back to the forums with any questions you run into while working with MongoDB. You can @ mention me (or Ramachandra I’m sure won’t mind a mention) in a public post, but there are lots of knowledgeable community members here each with their own expertise. That’s the great thing about community, we all get a chance to learn and teach and we all increase our knowledge from every post we read.
New & Unread Topics
Topic | Replies | Views | Activity |
---|---|---|---|
Custom role cannot create user | 3 | 418 | Jun 2024 |
Run mongodb from a read-only storage device? | 5 | 389 | Jul 2024 |
MongoDB log is flooded with SSL error warnings | 0 | 331 | Jul 2024 |
Why’s there no Community Server arm64 packages for Debian 12 (bookworm)? | 0 | 330 | Aug 2024 |
Reduce Mongo Docker logs | 0 | 131 | Jan 13 |