'Converting table head in CSV file to schema field
I am demanded to define a schema for a CSV file using Mongoose, but after I peeked through the CSV file, I found there are almost a hundred fields or columns in the CSV file. I know how to define a schema in Mongoose using only a few fields, but I am totally unsure how to define such schema. Is there an efficient way of doing that, such as reading through the head of the CSV and copy those heads into an javascript object and then pass the object to the mongoose.Schema()
Solution 1:[1]
Using this package https://www.npmjs.com/package/csvjson you can convert csv file to JSON.
Then secondly, you can convert the generated JSON to mongoose schema using this package, https://github.com/topliceanu/mongoose-gen.
You may need to edit the field types. I hope it works for you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | R?dvan Can |
