简体   繁体   中英

How to sort when parsing XML to mongodb

I'm beginner in JS. Example of XML file i cant upload.

I have a file that is parsed JS to mongo DB. How can I add a sorting there when prsing, which does not include null values ​​in priceService:fullXML.Report.ds[i].i[j]['$'].f?

Part of code when i need sorting

   if(fullXML.Report.ds[i].i){
    for(var j=0;j<fullXML.Report.ds[i].i.length;j++){
      detallization.tel[i].callsAll[j]={
        date:fullXML.Report.ds[i].i[j]['$'].d,
        oneService:fullXML.Report.ds[i].i[j]['$'].n,
        priceService:fullXML.Report.ds[i].i[j]['$'].f,
        time:fullXML.Report.ds[i].i[j]['$'].du,
      }
    }
 }

I need something:

   if(fullXML.Report.ds[i].i){
    for(var j=0;j<fullXML.Report.ds[i].i.length;j++)
     if(fullXML.Report.ds[i].i[j]['$'].f>0){
       detallization.tel[i].callsAll[j]={            
         date:fullXML.Report.ds[i].i[j]['$'].d,
         oneService:fullXML.Report.ds[i].i[j]['$'].n,
         priceService:fullXML.Report.ds[i].i[j]['$'].f,
         time:fullXML.Report.ds[i].i[j]['$'].du, 

But this solution does not work. Please help me.

Answer for my question

  

    if(fullXML.Report.ds[i].i){
            for(var j=0;j 0){
              detallization.tel[i].callsAll.push({
                date:fullXML.Report.ds[i].i[j]['$'].d,
                oneService:fullXML.Report.ds[i].i[j]['$'].n,
                priceService:fullXML.Report.ds[i].i[j]['$'].f,
                time:fullXML.Report.ds[i].i[j]['$'].du,
                })
              }
            }
         }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM