How to execute mongodb commands from bash shell

0 votes

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".

Jun 22, 2022 in Linux Administration by Korak
• 5,820 points
2,447 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Linux Administration

0 votes
2 answers

How do I use a shell script to SSH in to a remote machine to execute commands?

Sorry in advance for any formatting. Check out ...READ MORE

answered Feb 7, 2021 in Linux Administration by anonymous
17,306 views
0 votes
1 answer

How to find the first field from a file in Bash Shell?

Hi@akhtar, You can extract text from a file. ...READ MORE

answered Oct 20, 2020 in Linux Administration by MD
• 95,460 points
1,074 views
0 votes
1 answer

How to take input from user in bash script?

You can use if-else branch to check ...READ MORE

answered Jan 31, 2019 in Linux Administration by Omkar
• 69,220 points
1,134 views
0 votes
0 answers

Shell: How to call one shell script from another shell script?

I have two shell scripts, a.sh and ...READ MORE

Apr 14, 2022 in Linux Administration by Soham
• 9,710 points
542 views
0 votes
0 answers

How to set environment variables for bash from within powershell?

Using powershell how do I set the environment variables (here, particularly "ApiSecret") so ...READ MORE

Jun 3, 2022 in Linux Administration by Rahul
• 3,380 points
815 views
0 votes
0 answers

How to send control+c from a bash script?

I'm starting a number of screens in ...READ MORE

Jun 16, 2022 in Linux Administration by Rahul
• 3,380 points
757 views
0 votes
0 answers

How to detect the OS from a Bash script?

I would like to keep my .bashrc and .bash_login files in ...READ MORE

Jun 21, 2022 in Linux Administration by Korak
• 5,820 points
547 views
0 votes
0 answers

How to detect the OS from a Bash script?

I would like to keep my .bashrc ...READ MORE

Jun 22, 2022 in Linux Administration by Korak
• 5,820 points
578 views
0 votes
2 answers

how to loop through the content of a file using bash

#!/bin/bash for i in  `cat peptides.txt` do echo $i done READ MORE

answered Sep 5, 2020 in Linux Administration by Prakash K. Aithal
2,981 views
0 votes
1 answer

How to change the default shell in Linux?

1. Change the password file directly for ...READ MORE

answered May 24, 2019 in Linux Administration by Upasana
• 8,620 points
1,004 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP