I need to call mongoexport remotely and get the result from node.js
I used @GianfrancoP's answer but the syntax is deprecated. You'll now need to include the fieldnames you want to export. Here's updated syntax:
mongoexport --username user --password pass --host host --db database --collection coll --type=csv --fields fieldname
First, make sure the MongoDB port is opened and you can connect from the server. Then, use
mongoexport --username user --password pass --host host --db database --collection coll --type=csv --fields=displayName,emailAddress --query='{"status": "verified"}' -o users-YEAR-DAY-MONTH.csv
If the server it's in a public network make sure to use authentication.
https://docs.mongodb.com/manual/security/
Alternatively, it might be simpler to run an ssh command, run mongoexport
on the MongoDb server and then sftp
back the file (maybe zip it first).
More info on mongoexport