The purpose of this forum post is to automate the download of data from mongodb based on specific fields. At the end of this post, you should have an automated Windows Scheduller process running that downloads the data from a mongodb instance into a csv file.
Note that you also have the possibility to automate the download to csv as a pre-build plugin; this is not going to be covered in this post, but at the end you can find a reference about how to do so.
Make sure you have a working server and a connection to mongodb running.
For the purpose of this example, import the "mongo_sample.json" file into the collection "mongo_sample" of mongodb using the following command.
Please edit it to accommodate your mongodb installation and json file path:
c:\mongodb\bin\mongoimport --collection mongo_sample --file c:\sample\mongo_sample.json --jsonArray
Test the command to export your data using "mongoexport". In the example below, we want to export the data from the database called "test" and collection "mongo_sample". The fields that we want to export are "city", "loc", "pop", "state", and "_id".
Please edit the command to accommodate your mongodb installation and csv file path:
c:\mongodb\bin\mongoexport --db test --collection mongo_sample --csv --out c:/sample/zips.csv --fields _id,city,loc,pop,state
We are going now to create an executable file to run the command in the previous step. In a notepad, please write the command above and save the file as "mongotocsv.bat"
Create a scheduled task using the mongotocsv.bat process. Here you have more information about the Windows Scheduler.
In the Elasticube Manager, make sure to point to the csv file generated on the previous steps.
You also have the opportunity to automate the mongo export every time that the build runs. In this forum post you have information about creating a pre-build plugin
Please sign in to leave a comment.