Search code examples
mongodbcsvfieldmongoimport

mongoimport ignore field value 0


I have a lot of data in CSV with a lot of fields for which the value is 0.

I would like to import all that data into a collection, but ignore the fields when the value is 0 (not ignore the row, just the fied).

Without ignore the 0 fields, my command is : mongoimport --db merch --collection output --type csv --headerline --file export_hub_dev.csv

Is there any option with mongoimport which permits to do that ? For example something like --parseGrace skipField but with the 0 value ?

Or any other way to do that easily ?


Solution

  • You may first import the csv and then remove the fields by $UNSET. You need to run this for each fields one by one. The update format is

    db.collection.update(
       <query>,
       <update>,
       {
         upsert: <boolean>,
         multi: <boolean>,
         writeConcern: <document>,
         collation: <document>
       }
    )