Question
You starts a remote terminal in a linux machine that has network access to a MongoDB instance with ip 192.1.1.10. Now you need to export a collection 'logs' using mongoexport
tool. You do not have SSH access to that MongoDB machine. And, you are not allowed to install anything in this terminal. You can use the docker
which is already installed in the machine.
Answer:
docker run \ # start docker
--rm \ # remove the container when command finished
--network host \ # use host network in order to connect to remote Mongo, otherwise, network is isolated by default
mongo \ # use latest mongoDB image
mongoexport --collection logs --host 192.1.1.10 --port 27012 \ # run the tool
> logs # pipe the output collection jsons to a file
网友评论