Unverified Commit d1d92023 authored by Mark Stenglein's avatar Mark Stenglein
Browse files

Add function to read in data to the database

parent 0092dc0a
......@@ -17,8 +17,8 @@ var semesterSchema = new Schema({
session_templates: [
{
date_range: { type: String, required: true },
days: { type: String, required: true },
time: { type: String, required: true },
days: { type: String },
time: { type: String },
location: { type: String, required: true },
class_type: { type: String, required: true },
instructors: { type: String, required: true },
......
// grab the things we need
var mongoose = require('mongoose');
var Semester = require('../models/Semester');
var fs = require("fs");
//////
// DATA FILES HERE - TODO: Make this programmatic instead of hard coded
//////
var datafiles = [
'GMU2016F.min.json',
'GMU2016S.min.json'
]
var populateDB = function() {
emptySemesters(); // NOTE: this is an asynchronous call
for (var i = 0; i < datafiles.length; i++) {
var datafile = datafiles[i];
var semester = new Semester(JSON.parse(fs.readFileSync("./setup/dataFiles/" + datafile)));
semester.save(function(err) {
if (err) { console.error('Database Error!', err) }
else {console.log("write successful");}
})
}
}
// Empty collections
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment