Search code examples
databasemongodbmongoimportmongorestore

Mongoimport ignore leading zero in csv


I have a .CSV export file from a SQL Server database, with a phone number field (number type) that field values started with leading zero.

Leading zero is presented in the CSV file.

When I attempt to mongoimport it to DB (in string type) I find data imported without leading zero.

The target field number is string. How can I solve this problem?


Solution

  • you can specifically define the type of the field using the import option --columnsHaveTypes

    Instructs mongoimport that the field list specified in --fields, --fieldFile, or --headerline specifies the types of each field.

    MongoDB Manual