-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongo_mysql.js
More file actions
37 lines (31 loc) · 1.21 KB
/
mongo_mysql.js
File metadata and controls
37 lines (31 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require('dotenv').config();
const mongoose = require('mongoose');
const fs = require('fs')
mongoose.connect(process.env.MONGO_URL, { useNewUrlParser: true, useUnifiedTopology: true });
mongoose.connection.on('connected', () => main())
var userSchema = new mongoose.Schema({
naam: {type: String},
}, {collection: 'vragen'});
var User = mongoose.model('vragen',userSchema);
var SQL = `create table vraag
(
id int auto_increment,
naam varchar(255) not null,
antwoord_a varchar(255) null,
antwoord_b varchar(255) not null,
antwoord_c varchar(255) null,
antwoord_d varchar(255) null,
juiste_antwoord varchar(255) not null,
constraint vraag_pk
primary key (id)
);\n`
function main() {
User.find({}).then(vraag => {
vraag.forEach(v => {
var json = v.toJSON()
SQL += `INSERT INTO \`vraag\` (\`id\`, \`naam\`, \`antwoord_a\`, \`antwoord_b\`, \`antwoord_c\`, \`antwoord_d\`, \`juiste_antwoord\`) VALUES ('', '${json.naam}', '${json.antwoord_a}', '${json.antwoord_b}', '${json.antwoord_c}', '${json.antwoord_d}', '${json.juiste_antwoord}');\n`
})
fs.writeFileSync('./database.sql', SQL)
console.log('Saved vragen to database.sql')
})
}