How to get output of a script or query from MongoDB compass's mongosh to a .txt file on desktop


i was hoping someone would be able to assist

What i am trying to do is
1 - export the output of a query ran on mongosh on compass to a .txt file on my desktop
2 - get the output of a Javascript script to a .txt file on my desktop

is this possible to get done?

With mongosh command line you will get the output on the terminal with –eval. You may then redirect the output to a file.

With mongoexport you may specify –query and –out.