• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Quiz application using spring-data mongo db framework

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am planning to make sample quiz application using monogdb,Java using spring-data mongodb framework.
The application will be very simple. First page will display list of categories. like Sports,Politics.
When user will click on any category some random questions will be fetched from that category.
On a page one question will be displayed having four options. One or more than one of those can be correct answers.
Have designed the following schema -

I am planning to make it fast.. so for every question i want to skip the db roundtrip for fast loading.. I have following concerns -
  • Can i put all questions in some javascript variable and access them from there? But i am afraid it will also contain the answers..like user might see them by using firebug etc..
  • Shall i send only questions list(without answers) in frontend, and upon answering do a ajax call to check the answer if it is correct or not?


  • The other doubt is about categories - is the above schema is good?
    or shall i create a new collection for categories and put all question ids related to that category.

    Please share your views.
     
    Ranch Hand
    Posts: 10198
    3
    Mac PPC Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I did a similar application in the recent times. Here is what I did!

    I present the user with a List of exams, the user selects one exam and hits Start. I fetch all the questions for that exam, set thew first question with its answers and present it to the UI layer. After every click of the next button, I save the answer the user has selected, fetch the next question and answers from the database and repeat the process until the user has attempted all the questions. Upon clicking finish exam, I evaluate his results and present the final result.
     
    kuldeep sidhu
    Ranch Hand
    Posts: 37
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Joe Harry wrote:
    I present the user with a List of exams, the user selects one exam and hits Start. I fetch all the questions for that exam, set thew first question with its answers and present it to the UI layer. After every click of the next button, I save the answer the user has selected, fetch the next question and answers from the database and repeat the process until the user has attempted all the questions. Upon clicking finish exam, I evaluate his results and present the final result.



    Thanks Joe.
    Even i want to do the similar kind of application. the only difference is instead of showing answers at last, i want to show it per question like once attempted i will show the correct answer. So as per your case it was ok to do one database call at the end to fetch all the answers. But in my case it will be like 10 calls for 10 questions.
    And can you share the idea of your schema if you have done using mongo db. I want to know whether it will be good to save the correctanswer with the question itself(as i mentioned in first post) or create a new collection for question-answer combination.
     
    Joe San
    Ranch Hand
    Posts: 10198
    3
    Mac PPC Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The correct answer should be stored in the answer. The answer should know if it is a correct answer or not and not the question. All the question should know is the set of answers. Is your application a web based one? You can then use server side session to store this information. After each click of the user, you can check the information contained in the session.
     
    Rancher
    Posts: 2759
    32
    Eclipse IDE Spring Tomcat Server
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    1) If you have to cache the answer, I would keep the correct answer in a session variable. BTW, I don;t think you don't need to add this complication. It's better you make another roundtrip to MongoDB. Looking up the entry by id won't add too much overhead. If you want your application to be scalable, it's better you always retreive data from the MongDB
    2) The first option is better. If you are going to be looking up questions by category, just create an index on the category. Internally, MongoDB creates a structure that is similar to what your second proposal is.. except that it's better structured to retrieve data.
     
    catch it before it slithers away! Oh wait, it's a tiny ad:
    We need your help - Coderanch server fundraiser
    https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
    reply
      Bookmark Topic Watch Topic
    • New Topic