title: How to create mongoose schema with array of objects
body: <p>I have this json:</p>
  
  <pre><code>{
      "data": [
          "id": "1",
          "name": "Sample test",
          "description": "this is a sample test",
          "category": "tests",
          "points": 100,
          "startDate"​:​"2018-02-15 00:00:00"​,
          "endDate"​:​"2018-02-22 00:00:00"​,
          "isActive"​:​true​,
          "alreadyAnswered"​:​false​,
          "questions"​:[
              {
                  "id": 1,
                  "text": "What is your name",
                  "type": "text",
              },
              {
                  "id": 2,
                  "text": "What is your favorite color",
                  "type": "select",
                  "options": [
                      {
                          "id": 1,
                          "text": "Red",
                          "value": "red"
                      },
                      {
                          "id": 2,
                          "text": "Blue",
                          "value": "blue"
                      }
                  ]
              }
          ]
      ]
  }
  </code></pre>
  
  <p>I need to create this json into mongo database so I can get it via my node application.</p>
  
  <p>This is my current schema:</p>
  
  <pre><code>let TestSchema = new Schema({
      id: Number,
      name: String,
      description: String,
      category: String,
      points: Number,
      startDate: Date,
      endDate: Date,
      isActive: Boolean,
      alreadyAnswered: Boolean
  });
  </code></pre>
  
  <p>My greatest problem is I don't know how to add other objects into my schema to replicate the json, in MySQL I would do it with a hasmany relationship and add the correspondent id into the questions and options, but in this case I need to do via Mongo(create the json and get it via a route).</p>
  
  <p>How can I do that programatically?
  Thanks in advance.</p>