How can I use bash scripts to safely shut down the mongodb service process?

  mongodb, question

I directly kill mongodb’s service process, and the next time I start, I will be prompted to shut down.
I know that entering mongo’s program and entering mongo’s own shell can shut down the service, but how will I do it if I want to use bash?
I know mongo has a-eval parameter, which can run commands directly, but if I directly—eval “db.shutdownServer () “I am always prompted to use admin, but if I –eval “use admin; I don’t know how to correct my grammatical errors.

I found the answer to this question myself:

./mongo admin --eval "shutdownServer()"

Yes, of course, if you have a port or password, please add the corresponding parameters. The format can be found in./mongo-help
The reason why I have always asked this question before is that –help says that adding a user name requires -u username, which is similar to mysql, but I have tried

-u admin --eval "db.shutdownServer()"

Still no, I don’t know if it’s a bug.