Connecting to mongod, via cmd fails

I am using windows 10, first thing is that I try to open my mongod shell, it quits As it open. also by default there is no path “C:\data\db” the default db is on another path somewhere inside program files but whenever I try to connect to it the mongo shell, it doesn’t and says, “Attempted to create a lock file on a read-only directory: C:\Program Files\MongoDB\Server\4.4”}}"

mongod is used to start a mongod instance
mongo is used to connect to a running mongod instance

It appears you are trying to start mongod
Yes by default mongod looks for /data/db if you did not pass any parameters with mongod command
You can start mongod on a different port and dbpath by specifying another directory or create missing dir /data/db
mongod --port xyz --dbpath your_dir (say your home dir).Replace xyz with a valid port number other than default 27017
Once it is up yu can connect by
mongo --port xyz
Also on Windows you should be having a mongod running as service
Just use mongo to connect to it

I try to connect to default, i.e data\db but my mongo shell is connected somewhere to the another db. When I try to connect mongod to that another (“Default db”) the mongod refuse and bring up the error mentioned above.

Please show screenshots of what you ran and the errors you are getting

Are you not using IDE for this course?

Why you are using that directory?
Use some other directory like your home dir.It will work
The dir you specified is being used by default mongod.That is the reason it is giving lock file error on RO directory

why can’t I initiate that instance already stored by mongodb?

I have clarified in my first reply mongod is used to start mongod
mongo to connect to a running instance
Your mongod may be already up & running
Did you try to run mongo?
Just mongo which will connect you to your default mongod
You can also check this from your Windows services

You cannot run more than one mongod on the same port/dbpath

1 Like

I understood, thanks for your help.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.