Incomplete Output Issue When Running MongoDB JavaScript Using mongosh

Hi,
Currently we are using mongo to run the JavaScript files to get data.
Now we want to use mongosh to run .js files as mongo is deprecating in future releases.
we are experiencing the inclusion of irrelevant data at the top of our output files even after using ‘–quiet’ option. Specifically, we observe lines similar to:

'Prod [direct: other] eye_db>
Prod [direct: other] eye_db> … … … … … ’

And also if the output data is having 10000 records , it is showing 100 records and at the bottom
‘… 9900 records more`’ in output file

How to solve this?

@Pavan_Vinnakota can you share the script you are running and how you are running it?

Hi @Massimiliano_Marcon,
Thank you for the replay.

The script i am using is below

db.getMongo().setReadPref("secondary")

db.tracker.aggregate([
  {$match: {
      lastModifiedOn:{$gte:'2024/02/19'}, status: "inProgress"
  }},
  {$group: {_id: "$trackerId",count:{$sum:1}}},
  {$project:{count:"$count"}}]).forEach(function(doc){
print(doc._id+","+doc.count)
  }) ```

mongosh marketplace --authenticationDatabase marketplace -u <> -p <> --host host.in --port 27017 --quiet < file.js > data.csv


The output file is having this at top along with required data:

Prod [direct: other] marketplace>
Prod [direct: other] marketplace>
Prod [direct: other] marketplace> … … … … … … …


How to avoid this in output file.
Please suggest.

can you try with:

mongosh marketplace --authenticationDatabase marketplace -u <> -p <> --host host.in --port 27017 --quiet -f file.js > data.csv

Hi,
Working as expected.
Thank you for the support.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.