Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How to run MongoDB shell using mongos command?
The mongos command is used to start a MongoDB router process in sharded cluster deployments. It acts as an interface between client applications and the sharded cluster, routing queries to the appropriate shards.
Syntax
mongos --configdb <configReplSetName>/<host1:port1>,<host2:port2>
Basic mongos Command
To start the mongos router, specify the configuration replica set ?
mongos --configdb configReplSet/config1.example.com:27019,config2.example.com:27019,config3.example.com:27019
Common mongos Options
Here are the most frequently used mongos command options ?
mongos --configdb configReplSet/config1:27019,config2:27019 --port 27017 mongos --configdb configReplSet/config1:27019,config2:27019 --logpath /var/log/mongodb/mongos.log mongos --configdb configReplSet/config1:27019,config2:27019 --fork --logpath /var/log/mongodb/mongos.log
Key Parameters
| Parameter | Description | Example |
|---|---|---|
--configdb |
Config server replica set | configRS/host1:27019 |
--port |
Port for mongos to listen | --port 27017 |
--logpath |
Log file location | --logpath /var/log/mongos.log |
--fork |
Run as background process | --fork |
Connecting to mongos
Once mongos is running, connect using the mongo shell ?
mongo --host localhost --port 27017
Conclusion
The mongos command starts a MongoDB router for sharded clusters. It requires the --configdb parameter to specify configuration servers and acts as the entry point for client applications to access sharded data.
Advertisements
