-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create model with mongoose and insert three test records
Setup app for heroku.
- Loading branch information
1 parent
0b3926b
commit 3431175
Showing
5 changed files
with
271 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const mongoose = require('mongoose'); | ||
const student = require('../models/student'); | ||
|
||
mongoose.Promise = global.Promise; | ||
|
||
const saveStudent = (student) => { | ||
student.save().then(() => { | ||
console.log(`Saved student ${student}`); | ||
}, (e) => { | ||
console.log(`Unable to save ${student}`); | ||
}); | ||
}; | ||
|
||
const insertTestData = () => { | ||
const rudolf = new student.Student({ | ||
Vorname: 'Rudolf', | ||
Nachname: 'Grauberger', | ||
Matrikelnummer: 00000001, | ||
Studiengang: 'INF', | ||
Semester: 5, | ||
EMail: '[email protected]' | ||
}); | ||
|
||
const max = new student.Student({ | ||
Vorname: 'Max', | ||
Nachname: 'Mustermann', | ||
Matrikelnummer: 00000002, | ||
Studiengang: 'MI', | ||
Semester: 6, | ||
EMail: '[email protected]' | ||
}); | ||
|
||
const peter = new student.Student({ | ||
Vorname: 'Peter', | ||
Nachname: 'Mustermann', | ||
Matrikelnummer: 00000003, | ||
Studiengang: 'WI', | ||
Semester: 3, | ||
EMail: '[email protected]' | ||
}); | ||
|
||
saveStudent(rudolf); | ||
saveStudent(max); | ||
saveStudent(peter); | ||
} | ||
|
||
const initDatabase = (connectionString) => { | ||
mongoose.connect(connectionString); | ||
|
||
insertTestData(); | ||
}; | ||
|
||
module.exports = { | ||
initDatabase | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
// Definiert den Aufbau des Objekts | ||
const StudentSchema = new mongoose.Schema({ | ||
Vorname: { | ||
type: String | ||
}, | ||
Nachname: { | ||
type: String | ||
}, | ||
Matrikelnummer: { | ||
type: Number | ||
}, | ||
Studiengang: { | ||
type: String | ||
}, | ||
Semester: { | ||
type: Number | ||
}, | ||
EMail: { | ||
type: String | ||
} | ||
}); | ||
|
||
// Das muss ausgeführt werden, damit ein Constructor für Student zur Verfügung steht | ||
const Student = mongoose.model('Student', StudentSchema); | ||
|
||
module.exports = { | ||
Student | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters