title: How to insert/ update xml data in Mongodb with xml2js library
body: <p>I'm trying to understand the logic of how to import XML in MongoDB. I'd like to do this with JavaScript and xml2js library. Are there any good examples?</p>
  
  <p><strong>Steps:</strong></p>
  
  <ol>
  <li><p>Download xml to folder from XML feed</p></li>
  <li><p>Check whether data exists in MongoDB. If it does not, insert in collection.</p></li>
  <li><p>If data exists in the collection, check whether there is a change and if there are changes, update the document in collection.</p></li>
  </ol>
  
  <p>We are talking about sports scores, so XML changes depending on the game.</p>
  
  <p><strong>Example of XML:</strong></p>
  
  <pre><code>&lt;livescore updated="20.09.2016 09:44:23" sport="soccer"&gt;
  &lt;league country="argentina" name="Argentina: Primera Division" cup="False" id="2914" sub_id="29144"&gt;
  &lt;match alternate_id="4349375" alternate_id_2="4552948" commentary="True" date="20.09.2016" id="4466495" static_id="20091623378212337749" status="FT" time="00:15"&gt;
  &lt;home goals="0" id="2337821" name="Gimnasia L.P." /&gt;
  &lt;away goals="1" id="2337749" name="Atl. Rafaela" /&gt;
  &lt;events&gt;
  &lt;event assist="" assistid="" extra_min="" id="24542984" minute="9" player="E. Medaglia" playerid="2612790" result="" team="away" type="yellowcard" /&gt;
  &lt;event assist="" assistid="" extra_min="" id="24542985" minute="21" player="D. Imperiale" playerid="2580829" result="" team="home" type="yellowcard" /&gt;
  &lt;event assist="F. Luna" assistid="305493" extra_min="" id="24542986" minute="57" player="M. Bognino" playerid="2778704" result="[0 - 1]" team="away" type="goal" /&gt;
  &lt;event assist="" assistid="" extra_min="" id="24542987" minute="75" player="S. Paz" playerid="2766117" result="" team="away" type="yellowcard" /&gt;
  &lt;event assist="" assistid="" extra_min="" id="24542988" minute="87" player="D. Imperiale" playerid="2580829" result="" team="home" type="yellowred" /&gt;
  &lt;/events&gt;
  &lt;ht score="[0-0]" /&gt;
  &lt;ft score="[0-1]" /&gt;
  &lt;/match&gt;
  &lt;/league&gt;
  &lt;/livescore&gt;
  </code></pre>