Export to JSON, BSON, CSV doesn't show all potential values

zcoss shared this problem 5 years ago
Not a Problem

Hi,

We perform CSV exports for clients on one of our collections that's over 80GB large. Most exports to CSV work great, but recently I've noticed that performing an export will not always display all possible values. For instance, the documents (which come through a Mongoose schema first), all have an object called subVariables that stores different key:value pairs. But not all of the possible keys are listed in the checklist after clicking the Export to JSON, BSON, CSV button. What is strange, is that if I specifically search for a subscriber with a certain key that is missing and perform the export on that, the key will display (with others missing).

In the meantime, I've been moving the documents to another collection, performing a Schema Analysis on the collection, and finding all the possible values, then pasting them into the Export Script into the let fields = [] array, forcing the export to use all the values.

Has anyone else experienced this issue? I can include some images if that would be helpful. Thanks so much for the awesome software.. we love it and it's an essential part of our business.

Replies (2)

photo
1

Unlike exporting a JSON object, when you export a CSV, you need to determine the CSV header fields first, otherwise, the exported data will be messy. Due to MongoDB's schema-free feature, unless you traverse all the data (If the amount of data is large, this is unlikely), there is always the possibility of missing some fields.

photo
1

The export script generated by NoSqlBooster seems to rely on identifying all fields before exporting.

A solution is to modify

let jsonContent = mb.docsToJSON({ docs, fields, jsonType: exportType });
to

let jsonContent = mb.docsToJSON({ docs, jsonType: exportType });
which will export all fields for all documents, with the only downside that the fields will not be sorted (which isn't really an issue for backup purposes).

Leave a Comment
 
Attach a file