•An interactive JavaScript interface to MongoDB
•Used for –
•add new data
•query the existing data
•update the existing data
•remove the data
•perform administrative operations
•Separate Installation
•Can be installed on the same location as the server binary
MongoDB Shell
•Connect local
MongoDB instanceon default portmongosh
•Connect local MongoDB instance on different port
mongosh--port 8883
•Connect Remote MongoDB instance
mongosh--host mongodb0.example.com --port 8883
Connect MongoDB instance with Authentication
mongosh--host mongodb0.examples.com --port 28015 --username alice--password --authenticationDatabaseadmi
Configuring MongoDB Shell
Display Number of Operations
•Setup mongo shell prompt to display number of operations issued in the current session
•Code:
cmdCount= 1;
prompt = function() {
return (cmdCount++) + "> "
;}
•Result1>2>3>
Display Database and Hostname
Setup mongo shell prompt in the form of <database>@<hostname>$
•Code
host = db.serverStatus().host;
prompt = function()
{
return db+"@"+host+"$ ";
}
•Result
test@myHost1$
Display Up Time and Document Count
•Setup mongo shell prompt that contains the system up time and the number of documents in the current database
•Codeprompt = function() {return "Uptime:"+db.serverStatus().uptime+" Documents:"+db.stats().objects+" > ";}
•Result
•Uptime:5897 Documents:6 >
Accessing mongo Shell Help
Date
•NumberInt
No comments:
Post a Comment