db.shutdownServer()

When I use:

    use admin
    db.shutdownServer()

such commands do work for me on the console, but
mongo admin --eval 'db.shutdownServer()'
does not.

Why?

What’s the error message?

@admnll I’ll echo what @steevej-1495 did re the error message. However one thing to point out is in the first case, you’re in a connected Mongo shell presumably with appropriate privileges, while the second you’re connecting and executing the command which means you may need to provide the appropriate connection and credentials as necessary in addition to the command to execute.

HTH,
Mike

@steevej-1495 and @Mike_67094 I show you my screen.

@admnll I’m not sure the error you’re showing indicates anything out of the ordinary tbh. It looks like perhaps after you did the shutdown, the MongoShell was trying to see if was still connected (i.e. a health check of sorts). Or at a minimum detected the server went down, it tried to “reconnect” but couldn’t because the server was down.

And in the other window you can see where that shutdown has occurred, however the MongoShell would still be running, and likely if you issued another command directly after the shutdown would receive a similar message about connection.

As for the “mongo admin --eval 'db.shutdownServer()” it looks like you figured that part out, that would need to have been executed from the vagrant command line, not from within another mongoshell, etc…

HTH,
Mike

@Mike_67094, as you see, when I use

mongo admin --eval 'db.shutdownServer()'

the shell says me: SyntaxError: missing ; before statement,

and the server does not shut down, and something does not happen on the screen above.

But, using

    use admin
    db.shutdownServer()

the server shuts down.

@Mike_67094 It’s not really a matter of one command vs, the other working. The “mongo admin…” version is a command to be executed from outside mongo shell (i.e is launching the shell and executing the statement in the eval ‘…’. The second one is to be executed from within a running MongoShell.

So when you try to execute the first one from within a MongoShell, its gets the syntax error because its not a valid command for MongoShell, etc…

HTH,
Mike

:open_mouth: Thank you :+1:

1 Like