I'm trying to execute MongoDB command (for create DB) using .bat file.
For that I've tried:
cd C:\Program Files\MongoDB\Server\3.4\bin
mongo
mongo --eval "use MyDatabase"
pause
But it gives an error missing ; before statement @(shell eval):1:4
How can I solve this issue?
Side: I've already gone through MongoDB SyntaxError: missing ; before statement @(shell)
Can you try with :
cd Program Files\MongoDB\Server\3.4\bin
mongo.exe
mongo.exe --eval "use MyDatabase"
pause
I am using a .bat file which works properly and contains this
cd \Program Files\MongoDB\Server\3.2\bin
mongod.exe
pause
EDIT
I tested a file like this and it works fine (create db, collection and document)
mongodb.bat
cd \Program Files\MongoDB\Server\3.2\bin
mongo.exe db-mydb --eval "db.yourCollection.insert({key:'value'});"
pause
EDIT 2
If you want to run your .bat file on the background, i have made a .VBS file which works properly
mongodb.VBS
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\Path\To\Your\mongodb.bat" & Chr(34), 0
Set WshShell = Nothing
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With