How to execute mongo commands from bash?

MoienGK

I am trying to run this command from bash script:

 mongo 192.168.10.20:27000 --eval "use admin && db.shutdownServer() && quit()"

but i get this error :

[rs.initiate() && use admin && db.shutdownServer() && quit()] doesn't exist

how can i do it without using a js file?

Stennie

There are differences between interactive & scripted mongo shell sessions. In particular, commands like use admin are not valid JavaScript and will only work in an interactive shell session.

The working equivalent of your shutdown command line would be:

mongo 192.168.10.20:27000/admin --eval "db.shutdownServer()"

You can include the database to use in the connection string, and there is no need to quit from a scripted mongo shell session.

If you do need to change databases from a scripted session, there is a db.getSiblingDB() JavaScript function. An alternative way to write the shutdown command above would be:

 mongo 192.168.10.20:27000 --eval "db=db.getSiblingDB('admin');db.shutdownServer()"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to execute git commands from bash script?

From Dev

How to execute bash commands from C?

From Dev

How to execute shell commands in a loop from within a bash script?

From Dev

How does bash execute commands

From Java

How to execute mongo commands through shell scripts?

From Dev

Bash script to read from a file and execute commands

From Dev

Bash script to read from a file and execute commands

From Dev

Execute multiple commands in a terminal window from bash

From Java

How to execute a group of commands as another user in Bash?

From Dev

How to execute the following commands in a bash script?

From Dev

How to execute multiple commands in Bash, some in the background

From Dev

How to execute sudo commands with Expect & send commands in bash script?

From Dev

How to execute linux commands from R via bash under the Windows Subsystem for Linux (WSL)?

From Dev

How to read commands from a file and execute them?

From Dev

How to execute consecutive commands from history?

From Dev

How to execute commands from Haskell as root?

From Dev

How to execute library calls commands from shell?

From Dev

Bash Script execute commands from a file but if cancel on to jump on next one

From Dev

Execute commands from .bat file on Git Bash Terminal

From Dev

Shell out into zsh and execute commands from bash script

From Dev

Execute commands from .bat file on Git Bash Terminal

From Dev

How to open putty using batch and login then execute list of commands on bash

From Dev

how to execute frequently run bash commands with less keystrokes?

From Dev

Bash script: How to execute commands consecutively without waiting for the previous one?

From Dev

How to execute commands in docker container as part of bash shell script

From Dev

Bash script: How to execute commands consecutively without waiting for the previous one?

From Dev

How to edit-and-execute last two commands with `fc` in bash

From Dev

Pass commands to Mongo shell from bash script without halting interactive Mongo shell

From Dev

Bash tries to execute commands in heredoc

Related Related

  1. 1

    How to execute git commands from bash script?

  2. 2

    How to execute bash commands from C?

  3. 3

    How to execute shell commands in a loop from within a bash script?

  4. 4

    How does bash execute commands

  5. 5

    How to execute mongo commands through shell scripts?

  6. 6

    Bash script to read from a file and execute commands

  7. 7

    Bash script to read from a file and execute commands

  8. 8

    Execute multiple commands in a terminal window from bash

  9. 9

    How to execute a group of commands as another user in Bash?

  10. 10

    How to execute the following commands in a bash script?

  11. 11

    How to execute multiple commands in Bash, some in the background

  12. 12

    How to execute sudo commands with Expect & send commands in bash script?

  13. 13

    How to execute linux commands from R via bash under the Windows Subsystem for Linux (WSL)?

  14. 14

    How to read commands from a file and execute them?

  15. 15

    How to execute consecutive commands from history?

  16. 16

    How to execute commands from Haskell as root?

  17. 17

    How to execute library calls commands from shell?

  18. 18

    Bash Script execute commands from a file but if cancel on to jump on next one

  19. 19

    Execute commands from .bat file on Git Bash Terminal

  20. 20

    Shell out into zsh and execute commands from bash script

  21. 21

    Execute commands from .bat file on Git Bash Terminal

  22. 22

    How to open putty using batch and login then execute list of commands on bash

  23. 23

    how to execute frequently run bash commands with less keystrokes?

  24. 24

    Bash script: How to execute commands consecutively without waiting for the previous one?

  25. 25

    How to execute commands in docker container as part of bash shell script

  26. 26

    Bash script: How to execute commands consecutively without waiting for the previous one?

  27. 27

    How to edit-and-execute last two commands with `fc` in bash

  28. 28

    Pass commands to Mongo shell from bash script without halting interactive Mongo shell

  29. 29

    Bash tries to execute commands in heredoc

HotTag

Archive