Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mattias J Duffy
schedules
Commits
d1d92023
Unverified
Commit
d1d92023
authored
Jul 23, 2016
by
Mark Stenglein
Browse files
Add function to read in data to the database
parent
0092dc0a
Changes
2
Hide whitespace changes
Inline
Side-by-side
schedules/models/Semester.js
View file @
d1d92023
...
...
@@ -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
},
...
...
schedules/setup/populateDB.js
View file @
d1d92023
// 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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment