С помощью этого кода я не уверен, следует ли использовать examBoard.save()
после нажатия каждого вопроса на «экзамен-борд» или сразу после нажатия последнего вопроса на «экзамен-борд», как у меня в коде, который я поставил.Как использовать .save() в данных семян для mongodb
examBoard.create({
name: "AQA",
modules: [{
name: "c1",
topics: ["c1a", "c1b", "c1c"]
}, {
name: "c2",
topics: ["c2a", "c2b", "c2c"]
}, {
name: "c3",
topics: ["c3a", "c3b", "c3c"]
}],
function(err, examBoard) {
if (err) {
console.log("Failed to make new exam board\n" + err);
} else {
//=================================
//adding question to AQA exam board
//=================================
question.create({
text: "question 1a",
parts: [
["1a", "1b", "1c"],
["2a", "2b", "2c"],
["3a", "3b", "3c"]
]
}, function(err, question) {
if (err) {
console.log("Failed to make new question\n" + err);
} else {
examBoard.modules[0].topics[0].push(question);
console.log("New question made\n" + question);
}
});
question.create({
text: "question 1b",
parts: [
["1a", "1b", "1c"],
["2a", "2b", "2c"],
["3a", "3b", "3c"]
]
}, function(err, question) {
if (err) {
console.log("Failed to make new question\n" + err);
} else {
examBoard.modules[0].topics[1].push(question);
console.log("New question made\n" + question);
}
});
question.create({
text: "question 1c",
parts: [
["1a", "1b", "1c"],
["2a", "2b", "2c"],
["3a", "3b", "3c"]
]
}, function(err, question) {
if (err) {
console.log("Failed to make new question\n" + err);
} else {
examBoard.modules[0].topics[2].push(question);
console.log("New question made\n" + question);
}
});
question.create({
text: "question 2a",
parts: [
["1a", "1b", "1c"],
["2a", "2b", "2c"],
["3a", "3b", "3c"]
]
}, function(err, question) {
if (err) {
console.log("Failed to make new question\n" + err);
} else {
examBoard.modules[1].topics[0].push(question);
console.log("New question made\n" + question);
}
});
question.create({
text: "question 2b",
parts: [
["1a", "1b", "1c"],
["2a", "2b", "2c"],
["3a", "3b", "3c"]
]
}, function(err, question) {
if (err) {
console.log("Failed to make new question\n" + err);
} else {
examBoard.modules[1].topics[1].push(question);
console.log("New question made\n" + question);
}
});
question.create({
text: "question 2c",
parts: [
["1a", "1b", "1c"],
["2a", "2b", "2c"],
["3a", "3b", "3c"]
]
}, function(err, question) {
if (err) {
console.log("Failed to make new question\n" + err);
} else {
examBoard.modules[1].topics[2].push(question);
console.log("New question made\n" + question);
}
});
question.create({
text: "question 3a",
parts: [
["1a", "1b", "1c"],
["2a", "2b", "2c"],
["3a", "3b", "3c"]
]
}, function(err, question) {
if (err) {
console.log("Failed to make new question\n" + err);
} else {
examBoard.modules[2].topics[0].push(question);
console.log("New question made\n" + question);
}
});
question.create({
text: "question 3b",
parts: [
["1a", "1b", "1c"],
["2a", "2b", "2c"],
["3a", "3b", "3c"]
]
}, function(err, question) {
if (err) {
console.log("Failed to make new question\n" + err);
} else {
examBoard.modules[2].topics[1].push(question);
console.log("New question made\n" + question);
}
});
question.create({
text: "question 3c",
parts: [
["1a", "1b", "1c"],
["2a", "2b", "2c"],
["3a", "3b", "3c"]
]
}, function(err, question) {
if (err) {
console.log("Failed to make new question\n" + err);
} else {
examBoard.modules[2].topics[2].push(question);
examBoard.save();
console.log("New question made\n" + question);
}
});
console.log("New exam board made\n" + examBoard);
}
}
});
Ваше сообщение похоже на запрос обзора кода. Лучшим местом для вопросов является [Code Review StackExchange] (http://codereview.stackexchange.com/). – ishmaelMakitla
Хорошо спасибо за сказанное –