How to remove duplicate values inside a list in mongodb

后端 未结 4 1214
迷失自我
迷失自我 2021-01-02 20:35

I have a mongodb collection . When I do.

db.bill.find({})

I get,



        
4条回答
  •  春和景丽
    2021-01-02 21:33

    You can use a foreach loop with some javascript:

    db.bill.find().forEach(function(entry){
         var arr = entry.bill_codes;
         var uniqueArray = arr.filter(function(elem, pos) {
            return arr.indexOf(elem) == pos;
         }); 
         entry.bill_codes = uniqueArray;
         db.bill.save(entry);
    })
    

提交回复
热议问题