[COMPASS-4634] Compass does not appear to correctly export collections containing sub-documents to CSV format Created: 11/Feb/21  Updated: 29/Oct/23  Resolved: 08/May/23

Status: Closed
Project: Compass
Component/s: Import/Export
Affects Version/s: 1.25.0
Fix Version/s: 1.37.0

Type: Bug Priority: Minor - P4
Reporter: Harshad Dhavale Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: export-to-csv
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OS:
node.js / npm versions:
Additional info:


Attachments: File dictionary_test1_export_from_Compass_fullcollection.csv     PNG File export_from_Compass.png     File export_from_Compass_withQuery.csv     PNG File export_from_mongoexport.png     File mongoexp1-1.csv    
Issue Links:
Depends
depends on COMPASS-6425 importCSV() import function and tests Closed
depends on COMPASS-6519 Switch to using importCSV() Closed
depends on COMPASS-6520 Switch to using importJSON() Closed
depends on COMPASS-6582 Remove new export feature flag, remov... Closed
Epic Link: COMPASS-5576
Documentation Changes: Not Needed

 Description   

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.


Generated at Wed Feb 07 22:36:59 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.