You can try:
cd Program Files\MongoDB\Server\3.4\bin mongo.exe mongo.exe --eval "use MyDatabase" pause
I am using a .bat file that works correctly and contains this
cd \Program Files\MongoDB\Server\3.2\bin mongod.exe pause
EDIT
I tested such a file 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 in the background, I created a .VBS file that works correctly
mongodb.VBS
Set WshShell = CreateObject("WScript.Shell") WshShell.Run chr(34) & "C:\Path\To\Your\mongodb.bat" & Chr(34), 0 Set WshShell = Nothing
Hope this helps
source share