Skip to content

Instantly share code, notes, and snippets.

@hkirat
Created December 5, 2025 09:52
Show Gist options
  • Select an option

  • Save hkirat/22b497ba913993e1d8d025be33628803 to your computer and use it in GitHub Desktop.

Select an option

Save hkirat/22b497ba913993e1d8d025be33628803 to your computer and use it in GitHub Desktop.
const mongoose = require("mongoose");
const UserSchema = mongoose.Schema({
username: String,
password: String
})
const QuestionSchema = mongoose.Schema({
title: String,
options: [String]
})
const QuizSchema = mongoose.Schema({
title: String,
questions: [QuestionSchema]
})
const QuizModel = mongoose.model("quiz", QuizSchema);
const UserModel = mongoose.model("user", UserSchema);
async function main() {
await mongoose.connect("mongodb+srv://Warrior07A:[email protected]/harkirat_db2");
const q = await QuizModel.create({
title: "nodejs quiz"
})
q.questions.push({
title: "What is nodejs",
options: ["Runtime", "Framework"]
})
await q.save();
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment