`fields cannot be identical: ' ' and ' '` mongoimport error
I had a similar issue. I created an Excel spreadsheet, and in one column I had a linearized XML string. It seems that the save function of Excel did not handle one of the XML strings well, and created additional fields (columns) from it. Naturally I did not have any column headers for those additional columns, so when I tried importing to MongoDB, I got this error.
I was able to correct it by finding the problem-child XML string. Turns out that some of the spaces were actually tabs, and Excel used the tabs to separate the string across multiple cells. Once I replaced the tabs with a single space, the CSV saved correctly and mongoimport worked.
While I was following Adhil Maujahid's blog post on "Interactive Data Visualization with D3.js, DC.js, Python, and MongoDB" I encountered with this issue. After spending nearly an hour, I changed the command --headerline to -f 1,2,3,....44 (all the way untill "44"). Here 44 is the number of attributes in the file. So if you ever encounter with this issue, try out the work around. Please do let me know the logic behind this if you know the underlying reason.
The error: Mongo-tools is checking that the fields in your headerline are unique. This is because MongoDB doesn't support duplicated field names in documents.
From mongo-tools repo:
// NOTE: this means we will not support imports that have fields like
// a, a - since this is invalid in MongoDB
if field == latterField {
return fmt.Errorf("fields cannot be identical: '%v' and '%v'", field, latterField)
}
EDIT
I was able to reproduce this error message by creating a csv file with duplicate field names in the headerline.
It seems that your csv file has duplicate field names in the headerline ''
and ''
. Without seeing the actual file I imagine there is something like: field1,field2,,field3,,field4
in the headerline.
I had the exact same issue. I was opening up a CSV file in Excel to massage it and saving it back out again. While trying to import it into Mongo using "mongoimport" command I was getting the same error message that I had identical values. I checked the columns headings over and over to make sure there weren't any identical values.
I eventually tried re-saving the file from Excel using the "Windows Comma Separated (.csv)" option from the Format dropdown menu instead of the default "Comma Separated Values (.csv)" found in the "Common Format" section.
Worked perfectly.