0

I am using a windows batch file that will output a .js file into csv.

The .js file is a mongo query.

mongosh --host 10.1.0.1:27017 --username "username" --password "password" --authenticationDatabase admin --quiet C:\ActiveUsers1.js > C:\ActiveUsers.csv 
mongosh --host 10.1.0.1:27017 --username "username" --password "password" --authenticationDatabase admin --quiet C:\ActiveUsers2.js >> C:\ActiveUsers.csv
mongosh --host 10.1.0.1:27017 --username "username" --password "password" --authenticationDatabase admin --quiet C:\ActiveUsers3.js >> C:\ActiveUsers.csv

Sample result for each .js file

ActiveUsers1.js = 10
ActiveUsers2.js = 15
ActiveUsers3.js = 20

What I want to have on my ActiveUsers.csv file should be:

10
15
20

What I am getting is:

101520

I just upgraded into mongosh and I am not encountering this when using the old mongo shell (mongo).

Is there a way that I could control this on a .bat file?

JRA
  • 3
  • 2

1 Answers1

1

Add echo. after each mongosh to append a carriage return after each line.

    mongosh --host 10.1.0.1:27017 --username "username" --password "password" --authenticationDatabase admin --quiet C:\ActiveUsers1.js > C:\ActiveUsers.csv 
    echo.  >> C:\ActiveUsers.csv  
    mongosh --host 10.1.0.1:27017 --username "username" --password "password" --authenticationDatabase admin --quiet C:\ActiveUsers2.js >> C:\ActiveUsers.csv
    echo.  >> C:\ActiveUsers.csv
    mongosh --host 10.1.0.1:27017 --username "username" --password "password" --authenticationDatabase admin --quiet C:\ActiveUsers3.js >> C:\ActiveUsers.csv
    echo.  >> C:\ActiveUsers.csv 
RealHowTo
  • 128
  • 4
  • Hi @RealHowTo I got it to work. However there is a single space after the ActiveUsers1.js and ActiveUsers2.js is there a way to remove this? – JRA Sep 09 '22 at 03:54
  • 1
    Okay I got it to work. I just removed the spacing after echo. >> C:\ActiveUsers.csv into echo.>> C:\ActiveUsers.csv – JRA Sep 09 '22 at 04:00