Created
December 5, 2025 09:52
-
-
Save hkirat/22b497ba913993e1d8d025be33628803 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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