Export MongoDB to CSV Using File Name Variable
<p>I have a MongoDB that houses data from a web scrape that runs weekly via Scrapy. I'm going to setup a cron job to run the scrape job weekly. What I would like to do is also export a CSV out of MongoDB using mongoexport however I would like to inject the current date into the file name. I've tried a few different methods without much success. Any help would be greatly appreciated! For reference, my current export string is: mongoexport --host localhost --db glimpsedb --collection scrapedata --csv --out scrape-export.csv --fields dealerid,unitid,seller,street,city,state,zipcode,rvclass,year,make,model,condition,price</p>

<p>So, ideally the file name would be scrape-export-current date.csv</p>

<p>Thanks again!</p>

<p>Replace <code>--out scrape-export.csv</code> in your command with <code>--out scrape-export-$(date +"%Y-%m-%d").csv</code></p>

<p>It'll create filenames in the format <code>scrape-export-2016-09-05</code></p>

python mongodb scrapy mongoexport