3

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?

1 Answer 1

5

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:

MariaDB/MySQL Security Essentials – Disable System Commands

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.