Explorar o código

Create model for lecture questions.

Lee Morgan %!s(int64=4) %!d(string=hai) anos
pai
achega
1a816a9e7b
Modificáronse 1 ficheiros con 33 adicións e 0 borrados
  1. 33 0
      models/question.js

+ 33 - 0
models/question.js

@@ -0,0 +1,33 @@
+const mongoose = require("mongoose");
+
+const AnswerSchema = new mongoose.Schema({
+    name: String,
+    content: {
+        type: String,
+        required: true
+    },
+    createdAt: {
+        type: Date,
+        default: new Date()
+    }
+});
+
+const QuestionSchema = new mongoose.Schema({
+    name: String,
+    title: {
+        type: String,
+        required: true
+    },
+    content: {
+        type: String,
+        required: true,
+        minlength: 15
+    },
+    answers: [AnswerSchema],
+    createdAt: {
+        type: Date,
+        default: new Date()
+    }
+});
+
+module.exports = mongoose.model("Question", QuestionSchema);