How can I execute shell (bash) commands from within the MongoDB client?
With MySQL client:
system (!) Execute a system shell command.
Is there something similar for MongoDB?
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.Sign up to join this community
There are a number of system command equivalents available:
ls() mkdir() hostname() pwd() sleep() (not a system command, but similar functionality)
It should be noted that these are all executed on the client (local) machine, not the server. There is no general construct for executing arbitrary system commands that I know of in the shell. To be honest, I suspect that is intentional because it would be a security nightmare even on the client side.
Allowing arbitrary commands to be executed from your product (database or not) is a massive potential security hole because instead of being vulnerable to just your own issues, you are now liable for any security bugs in any other system utility people choose to install.
Hence the potential for the nightmare - I can't say for sure, but I'll bet the MySQL devs would love to get rid of that command. Here's an example of someone patching the client to get rid of it: