
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
How to stop MongoDB in a single command?
In order to stop MongoDB in a single command, use the following syntax −
mongo --eval "db.getSiblingDB('admin').shutdownServer()"
Let us implement the above syntax in order to stop MongoDB in one command.
First, use the shortcut key −
Ctrl + C;
The query is as follows −
C:\Program Files\MongoDB\Server\4.0\bin>mongo --eval "db.getSiblingDB('admin').shutdownServer()"
The following is the output − displaying the shutdown of the MongoDB server −
MongoDB shell version v4.0.5 connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb Implicit session: session { "id" : UUID("c0337c02-7ee2-45d9-9349-b22d6b1ffe85") } MongoDB server version: 4.0.5 server should be down... 2019-03-14T21:56:10.327+0530 I NETWORK [js] trying reconnect to 127.0.0.1:27017 failed 2019-03-14T21:56:11.331+0530 I NETWORK [js] reconnect 127.0.0.1:27017 failed failed 2019-03-14T21:56:11.333+0530 I QUERY [js] Failed to end session { id: UUID("c0337c02-7ee2-45d9-9349-b22d6b1ffe85") } due to SocketException: socket exception [CONNECT_ERROR] server [couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: No connection could be made because the target machine actively refused it.]
To begin MongoDB, try this −
C:\Program Files\MongoDB\Server\4.0\bin>mongod
The following is the output −
Let us open the command prompt and use the command mongo −
C:\Program Files\MongoDB\Server\4.0\bin>mongo
The following is the output −
- Related Articles
- How to select a single field in MongoDB?
- How to pop a single value in MongoDB?
- How to return only a single property “_id” in MongoDB?
- How to update a single field in a capped collection in MongoDB?
- How to insert multiple rows in a table using a single INSERT command in program?
- How to find only a single document satisfying the criteria in MongoDB?
- How to stop a loop with a stop button in Tkinter?
- MongoDB findOneAndUpdate() to update a single document
- How to run MongoDB shell using mongos command?\n
- How to connect to my MongoDB table by command line?
- How to check if a process is exited from the system after executing Stop-Process command in PowerShell?
- What keyboard command we have to stop an infinite loop in Python?
- How to remove all documents from a collection except a single document in MongoDB?
- Decrement only a single value in MongoDB?
- Update only a single document in MongoDB

Advertisements