Saturday, 18 March 2017

How do i design a json result in mongoose?

My goal is really simple, I want to design this particular json result into mongoose data structure.

Json example

{  
         "question": "Who was the 13th president of the United States?",
         "choice_1": "Millard Fillmore",
         "choice_2": "Zachary Taylor",
         "choice_3": "Franklin Pierce",
         "choice_4" :"James K. Polk",
         "answer" :"choice_1"
      },

My goal is to transform this json design into mongoose design, and my attempt so far.

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const QuestionSchema = new Schema({
    question: String,
    choice_1: String,
    choice_2: String,
    choice_3: String,
    choice_4: String,
    answer: String
});

The real question is, how would I put either one of the choice's keys in the answer attribute's field?



via airsoftFreak

No comments:

Post a Comment