How to implement mongo export in n8n

Hi team,

I have a use-case to get the data from mongoDB(by using query), convert that to CSV or Excel, and send a mail with an attachment of data to another team. Normally we used mongoexport and send the data using SMTP.

How can we achieve this in n8n, Can anyone tell me the process?


Hey @Swaroop_Nagaraju!

Welcome to the community :sparkling_heart:

The following are the steps I would take:

  1. Use the MongoDB node to fetch the data from MongoDB.
  2. Optional: Use the Function node to convert the data into an appropriate format. This is only required if the incoming data is not in the desired format.
  3. Use the Spreadsheet File node to write the data in CSV format.
  4. Use the Send Email node to send the file as an attachment.

I hope this helps :slight_smile:

It works for me, Thank you @harshil1712
I have one more query, How to pass dynamic values to the mongo query. i.e for example db.collectionname.find({startdate:{$gt:“date1”, $lt:“date2”} }), here date1 and date2 are dynamic values.

Hey @Swaroop_Nagaraju! In that case you will have to use Expressions.

Once again thank a lot @harshil1712