I'm trying to execute a mongodb query in a single command so I can run a batch script from within windows software. The mongodb database is already built, here are my windows console commands and cli query that work:
C:\Program Files\MongoDB\Server\3.0\bin>mongo ds045565-a1.mongolab.com:45565/heroku_mydatabase
2017-09-01T09:14:05.196+0100 I CONTROL Hotfix KB2731284 or later update is not installed, will zero-out data files
MongoDB shell version: 3.0.7
connecting to: ds045565-a1.mongolab.com:45565/heroku_mydatabase
rs-ds045565:PRIMARY> db.auth("myusername","mypassword");db.getCollection('94081_DS_FuelNBS').find({})
{ "_id" : ObjectId("58ab4ae3bc5cf82663236b4f"), "code" : "D", "description" : "Diesel", "lastModified" : ISODate("2017-02-20T20:00:35.680Z") }
{ "_id" : ObjectId("58ab4ae3bc5cf82663236b50"), "code" : "H", "description" : "Hydrogen", "lastModified" : ISODate("2017-02-20T20:00:35.680Z") }
{ "_id" : ObjectId("58ab4ae3bc5cf82663236b51"), "code" : "P", "description" : "Petrol", "lastModified" : ISODate("2017-02-20T20:00:35.680Z") }
rs-ds045565:PRIMARY> exit
bye
If I then try to execute as a single windows command I do not get any response output other than the error messages:
C:\Program Files\MongoDB\Server\3.0\bin>mongo ds045565-a1.mongolab.com:45565/heroku_mydatabase mymongodbcommands.txt > output.txt
C:\Program Files\MongoDB\Server\3.0\bin>
Here is the contents of mymongodbcommands.txt and output.txt
mymongodbcommands.txt:
db.auth("myusername","mypassword");db.getCollection('94081_DS_FuelNBS').find({})
output.txt
2017-09-01T09:15:41.604+0100 I CONTROL Hotfix KB2731284 or later update is not installed, will zero-out data files
MongoDB shell version: 3.0.7
connecting to: ds045565-a1.mongolab.com:45565/heroku_mydatabase