Currently, I am faced with the task of importing a JSON file containing embedded objects into MongoDB. I need to ensure that the document format remains unchanged during the import process. My main challenge lies in creating or modifying a function/method that will allow me to import the file while associating the _id within the sport-events array loop (in this case, simplified to just one sports-event array for brevity).
To rephrase my question: How can I import only the data within the sports-event array without altering the rest of the document structure?
JSON Document:
{
"sports-content": {
"sport-event": [{
"event-metadata": {
"league": "NCAA Basketball",
"event-type": "0",
"league-details": "NCAAB",
"event-date-time": "12/18/2015 07:00 PM",
"eventNum": "3000460",
"status": "",
"off-the-board": "False"
},
"team": [{
"team-metadata": {
"alignment": "Home",
"nss": "526",
"openNum": "526",
"name": {
"full": "Clemson"
}
},
"wagering-stats": {
"wagering-straight-spread": {
"bookmaker-name": "BetOnline",
"active": "true",
"line": "1.5",
"money": "-110",
"context": "current"
}
},
"team-stats": {
"score": "0"
}
}, {
"team-metadata": {
"alignment": "Away",
"openNum": "525",
"nss": "525",
"name": {
"full": "South Carolina"
}
},
"wagering-stats": {
"wagering-straight-spread": {
"bookmaker-name": "BetOnline",
"active": "true",
"line": "-1.5",
"money": "-110",
"context": "current"
}
},
"team-stats": {
"score": "0"
}
}]
}],
"sports-meta-data": {
"doc-time": "42353.5979256944"
}
}
}
Inside Meteor server.js wrapped in Meteor.startup:
if (SportEventsFeed.find().count() === 0) {
console.log("Importing private/products.json to db")
var data = JSON.parse(Assets.getText("ncaab.json"));
data.forEach(function (item, index, array) {
SportEventsFeed.insert(item);
})
}