I searched and found that one can use --eval but this does not work from CLI as you were inside mongodb shell.
For example I can not show databases with --eval
mongo -u root -p pass --eval "show dbs"
MongoDB shell version v4.2.18
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("80746969-2c86-45dc-603f-7f98882e578c") }
MongoDB server version: 4.2.18
2022-03-10T15:33:22.711+0000 E QUERY [js] uncaught exception: SyntaxError: unexpected token: identifier :
@(shell eval):1:5
2022-03-10T15:33:22.711+0000 E - [main] exiting with code -4
I was hoping there is something like mysql's mysql -e "show databases".