6

I installed mongodb in VS code by npm install mongodb. And again I downloaded mongodb from official website and installed it as a windows service since I don't know if installing in vscode with npm is enough. It worked for a while.

and now it doesn't work as my database connection with mongoose fails and nothing is running in 27017 port in localhost. Seems like server stopped.

how to restart mongodb server? what's the CLI/terminal command etc for that?

Pretty_Girl
  • 197
  • 1
  • 2
  • 10

4 Answers4

10

On debian/ubuntu

sudo service mongod restart

Daphoque
  • 4,421
  • 1
  • 20
  • 31
7

Mongodb Services

Go to services via start button and check for the MongoDB services shown in below pic. And rest steps you can follow which @apoorva has mentioned.

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
Dileephell
  • 620
  • 2
  • 7
  • 18
4

Open a mongo shell and execute,

use admin
db.shutdownServer()

You may start again with mongod.

Learn more here, https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/#StartingandStoppingMongo-SendingshutdownServer%28%29messagefromthemongoshell

Hasan
  • 247
  • 7
  • 22
2

If You Installed MongoDB as a Windows Service The MongoDB service is started upon successful installation.(please check on the below path)

To begin using MongoDB, connect a mongo.exe shell to the running MongoDB instance. Either:

From Windows Explorer/File Explorer, go to C:\Program Files\MongoDB\Server\4.4\bin\ directory and double-click on mongo.exe.

Or, open a Command Interpreter with Administrative privileges and run:

"C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe"

for more details check. : https://treehouse.github.io/installation-guides/windows/mongo-windows.html

Also, you first need to start the mongodb daemon for your connections to listen then you should connect using mongoose.

Apoorva Chikara
  • 8,277
  • 3
  • 20
  • 35
  • This error shows in cmd "No connection could be made because the target machine actively refused it" – Pretty_Girl Jan 21 '21 at 11:49
  • First of all check the firewall setting and port 27017 is listening. If port is listening try to follow these steps: https://stackoverflow.com/questions/23726684/mongodb-on-a-windows-7-machine-no-connection-could-be-made, else change policy for that port in firewall (https://desk.zoho.com/portal/simlabsoftware/en/kb/articles/how-to-disable-firewall-on-specific-port). – Apoorva Chikara Jan 21 '21 at 12:06