Uploaded image for project: 'Compass '
  1. Compass
  2. COMPASS-4634

Compass does not appear to correctly export collections containing sub-documents to CSV format

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.37.0
    • Affects Version/s: 1.25.0
    • Component/s: Import/Export
    • Environment:
      OS:
      node.js / npm versions:
      Additional info:

      Problem Description

      When trying to export collections containing sub-documents, from Compass in CSV format, the fields from the sub-documents get exported as individual fields, rather than showing up under the sub-document field. I tested this with latest Compass Version 1.25.0.

      This behavior is not observed when exporting to CSV via mongorestore.

      Please refer to the reproducer steps below that explains this in detail.

      Steps to Reproduce

      Reproducer:

      1. Inserted a collection with dictionaries and arrays like this:

      replset:PRIMARY> db.dictionary_test1.find().pretty()
      	{
      		"_id" : 1,
      		"dict1" : [
      			{
      				"field11" : 111,
      				"sub_dict1" : {
      					"field11_1" : "AAAA"
      				}
      			}
      		],
      		"dict2" : {
      			"field222" : 222,
      			"sub_dict2" : {
      				"field22_2" : "BBB"
      			}
      		}
      }
      

      2. Exported the collection in CSV format from Compass > Collection > Export Collection.

      3. Opened the Compass-exported CSV in Excel, which shows as follows:

      We observe that the sub-fields from dict2, specifically dict2.field222 and dict2.sub_dict2.field22_2, have been moved to separate columns. This happens with both "Export Full Collection" as well as with the "Export query with filters option" in Compass > Collection > Export Collection.

      4. Exported the collection in CSV format using mongoexport, as follows:

      mongoexport --port 39900 --db test --collection dictionary_test1 --fields _id,dict1,dict2  --type=csv --out mongoexp1.csv
      

      5. Opened the mongoexport-exported CSV in Excel, which shows as follows:

      We observe that the field dict2 and its sub-fields show correctly in the same column.

      Expected Results

      The sub-document field dict2 should show correctly in the exported output, as seen in the output generated by mongoexport.

      Actual Results

      The fields from the sub-documents, specifically dict2.field222 and dict2.sub_dict2.field22_2, get exported as individual fields, rather than showing up under field dict2.

        1. mongoexp1-1.csv
          0.1 kB
        2. export_from_mongoexport.png
          export_from_mongoexport.png
          23 kB
        3. export_from_Compass.png
          export_from_Compass.png
          23 kB
        4. export_from_Compass_withQuery.csv
          0.1 kB
        5. dictionary_test1_export_from_Compass_fullcollection.csv
          0.1 kB

            Assignee:
            Unassigned Unassigned
            Reporter:
            harshad.dhavale@mongodb.com Harshad Dhavale
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: