Hope this is not too late to help, but here is what I will do:
- Request data in CSV format and save it in memory or file.
- Parsing CSV data to convert each row into an object.
- For each object, use
Model.create() to create a new record.
First you need to create a model from your schema:
var Rank = db.model('Rank', rankSchema);
Then you can analyze the block of CSV text (whether you read it from a file or execute it immediately after your request is up to you.) I created my own dummy variable data , since I do not have access to api, but so far your the data is CSV newline delimited strings, this should work:
var data = '' + '9,386,1,451,Super Kancheong Style,22586,318793803,LaF,D,1,0,0,1,0\n' + '9,386,2,119,Storm of Swords,25365,293053897,LaF,D,1,0,0,1,0\n' + '9,386,3,33,eug gave it to mak gangnam style,43501,212637806,LaF,H,1,0,0,1,0\n' + '9,386,4,128,Justpickupgirlsdotcom,22628,201606479,LaF,H,1,0,0,1,0\n' + '9,386,5,300,One and Done,22100,196130870,LaF,H,1,0,0,1,0\n'; data = data.split('\n'); data.forEach(function(line) { line = line.split(','); if (line.length != 14) return; var new_rank = { serverid: line[0], resetid: line[1], rank: line[2], countryNumber: line[3], name: line[4], land: line[5], networth: line[6], tag: line[7], gov: line[8], gdi: line[9], protection: line[10], vacation: line[11], alive: line[12], deleted: line[13] }; Rank.create(new_rank, function(err, rank) { console.log('Created new rank!', rank); }); });
You can put this in a script and run it every 5 minutes using the cron job. On my Mac, I would edit my cron file with crontab -e , and I would set up a job with this line:
*/5 * * * * /path/to/node /path/to/script.js > /dev/null