Parse json into a series of documents in a collection using a for or foreach loop best? [meteor] -


i have meteor app pulls data in external api. simplicity sake we'll like...

var foo = meteor.http.call("get", "api-endpoint-url-here"); 

and inserts data collection...

    bar = new mongo.collection("bar");     bar.insert({       results: foo     });  

the json array (e.g. foo) includes number of individual records each of has it's own id number , corresponding data. i'm presently using json.parse establish array , looping through array create individual documents using _.each

 var fooparsed = json.parse(foo.content)  var fooarray = fooparsed.results;  _.each(fooarray, function(records) {    bar.insert ({      record: record    });  }); 

for it's crude aside - i've heard using foreach preferred performance. general consensus , thoughts on how streamline , implement such loop in instance?

in case it's helpful else in future - here's netted out

fooarray.foreach(function(item) {   bar.insert({     _id: item.id,     description: description,   });   });  

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -