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?

Paul White
95.4k30 gold badges440 silver badges689 bronze badges
asked Aug 25, 2015 at 11:32

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

Paul White
95.4k30 gold badges440 silver badges689 bronze badges
answered Aug 25, 2015 at 14:13
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.