I am new to moogoose/mongodb and I'm trying to import data. I have a REGIONS.model.js file ...
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var REGIONS = new Schema({
CODE: String,
DESCRIPTION_FRANCAISE: String,
DESCRIPTION_ANGLAISE: String
});
module.exports = mongoose.model('REGIONS', REGIONS);
and a REGIONS.TXT file ...
"01","Bas-Saint-Laurent","Bas-Saint-Laurent"
"02","Saguenay/Lac-Saint-Jean","Saguenay/Lac-Saint-Jean"
"03","Capitale-Nationale","Capitale-Nationale"
"04","Mauricie","Mauricie"
"05","Estrie","Estrie"
"06","Montréal","Montréal"
"07","Outaouais","Outaouais"
"08","Abitibi-Témiscamingue","Abitibi-Témiscamingue"
"09","Côte-Nord","Côte-Nord"
"10","Nord-du-Québec","Nord-du-Québec"
"11","Gaspésie/Iles-de-la-Madeleine","Gaspésie/Iles-de-la-Madeleine"
"12","Chaudière-Appalaches","Chaudière-Appalaches"
"13","Laval","Laval"
"14","Lanaudière","Lanaudière"
"15","Laurentides","Laurentides"
"16","Montérégie","Montérégie"
"17","Centre-du-Québec","Centre-du-Québec"
"50","Autres provinces","Other provinces"
"70","Etats-Unis","USA"
"80","Autres pays","Other countries"
and I would like to import the REGIONS.TXT's data into a mongodb db document that respects the REGIONS Schema.
In fact I will have multiple TXT files that I will need to import daily and that will need to match the corresponding Schema. (There are no headers in the *.TXT files)
*UPDATED to explain why it's not a duplicate,
I do not wish to hardcode the list of the Schema's keys and use them in a hardcoded function that aggregates these with their values since I have lot of Schemas and corresponding data files (*.TXT).
I guess I would need to "scan" the Schema (which has the same name as the TXT file) and dynamically "build" the function. Or maybe there's something built in mongoose?
Many thanks for your time and help.