Suppose that you are given a collection of JSON documents that represent a database of multiple choice exams taken by students. Write mongoDB queries to answer the following questions:
1. Determine the total number of exams.
The following json file is only an example to illustrate what the data looks like. The actual data has unique optionid and questionid.
{ name:’Smith’, id:159008743, courseId:’198:111’, semester:’Sp2018’, examNumber:1, totalQuestions:10, totalCorrect:8, percentage:0.8, grade:’B’, date_submitted:’04-25-2018’, time_submitted:’19:25:24’, room:’Hill 363’, computerNumber:5, ip:’198.253.128.5’, questions:[ { number:1, questionid:34532, questiontext:’Question 1’, answers:[ { option:’A’, optionid:384729, optiontext:’Option A’, correct:false, answered:false }, { option:’B’, 1 optionid:384734, optiontext:’Option B’, correct:false, answered:false },{ option:’C’, optionid:384249, optiontext:’Option C’, correct:true, answered:true },{ option:’D’, optionid:3834223, optiontext:’Option D’, correct:false, answered:false }] },{ number:2, questionid:34325, questiontext:’Question 2’, answers:[ { option:’A’, optionid:384729, optiontext:’Option A’, correct:false, answered:false },{ option:’B’, optionid:384729, optiontext:’Option B’, correct:false, answered:false },{ option:’C’, optionid:384729, optiontext:’Option C’, correct:false, answered:false },{ option:’D’, 2 optionid:384729, optiontext:’Option D’, correct:true, answered:true }] },{ number:3, questionid:34532, questiontext:’Question 1’, answers:[ { option:’A’, optionid:384729, optiontext:’Option A’, correct:true, answered:true },{ option:’B’, optionid:384729, optiontext:’Option B’, correct:false, answered:false },{ option:’C’, optionid:384729, optiontext:’Option C’, correct:false, answered:false },{ option:’D’, optionid:384729, optiontext:’Option D’, correct:false, answered:false }] },{ number:4, questionid:34532, questiontext:’Question 1’, answers:[ { option:’A’, 3 optionid:384729, optiontext:’Option A’, correct:true, answered:true },{ option:’B’, optionid:384729, optiontext:’Option B’, correct:false, answered:false },{ option:’C’, optionid:384729, optiontext:’Option C’, correct:false, answered:false },{ option:’D’, optionid:384729, optiontext:’Option D’, correct:false, answered:false }] },{ number:5, questionid:34532, questiontext:’Question 1’, answers:[ { option:’A’, optionid:384729, optiontext:’Option A’, correct:false, answered:false },{ option:’B’, optionid:384729, optiontext:’Option B’, correct:false, answered:false },{ option:’C’, 4 optionid:384729, optiontext:’Option C’, correct:false, answered:false },{ option:’D’, optionid:384729, optiontext:’Option D’, correct:true, answered:true }] },{ number:6, questionid:34532, questiontext:’Question 1’, answers:[ { option:’A’, optionid:384729, optiontext:’Option A’, correct:true, answered:true },{ option:’B’, optionid:384729, optiontext:’Option B’, correct:false, answered:false },{ option:’C’, optionid:384729, optiontext:’Option C’, correct:false, answered:false },{ option:’D’, optionid:384729, optiontext:’Option D’, correct:false, answered:false }] }, 5 { number:7, questionid:34532, questiontext:’Question 1’, answers:[ { option:’A’, optionid:384729, optiontext:’Option A’, correct:false, answered:true },{ option:’B’, optionid:384729, optiontext:’Option B’, correct:false, answered:false },{ option:’C’, optionid:384729, optiontext:’Option C’, correct:true, answered:false },{ option:’D’, optionid:384729, optiontext:’Option D’, correct:false, answered:false }] },{ number:8, questionid:34532, questiontext:’Question 1’, answers:[ { option:’A’, optionid:384729, optiontext:’Option A’, correct:false, answered:false },{ option:’B’, 6 optionid:384729, optiontext:’Option B’, correct:false, answered:false },{ option:’C’, optionid:384729, optiontext:’Option C’, correct:false, answered:false },{ option:’D’, optionid:384729, optiontext:’Option D’, correct:true, answered:true }] },{ number:9, questionid:34532, questiontext:’Question 1’, answers:[ { option:’A’, optionid:384729, optiontext:’Option A’, correct:false, answered:false },{ option:’B’, optionid:384729, optiontext:’Option B’, correct:false, answered:false },{ option:’C’, optionid:384729, optiontext:’Option C’, correct:true, answered:true },{ option:’D’, 7 optionid:384729, optiontext:’Option D’, correct:false, answered:false } ] }, { number:10, questionid:34532, questiontext:’Question 1’, answers:[ { option:’A’, optionid:384729, optiontext:’Option A’, correct:true, answered:false }, { option:’B’, optionid:384729, optiontext:’Option B’, correct:false, answered:false }, { option:’C’, optionid:384729, optiontext:’Option C’, correct:false, answered:true }, { option:’D’, optionid:384729, optiontext:’Option D’, correct:false, answered:false } ] } ] } 8
> db.mycol.insert({ name:’Smith’, id:159008743,
courseId:’198:111’, semester:’Sp2018’, examNumber:1,
totalQuestions:10, totalCorrect:8, percentage:0.8, grade:’B’,
date_submitted:’04-25-2018’, time_submitted:’19:25:24’, room:’Hill
363’, computerNumber:5, ip:’198.253.128.5’, questions:[ { number:1,
questionid:34532, questiontext:’Question 1’, answers:[ {
option:’A’, optionid:384729, optiontext:’Option A’, correct:false,
answered:false }, { option:’B’, 1 optionid:384734,
optiontext:’Option B’, correct:false, answered:false },{
option:’C’, optionid:384249, optiontext:’Option C’, correct:true,
answered:true },{ option:’D’, optionid:3834223, optiontext:’Option
D’, correct:false, answered:false }] },{ number:2,
questionid:34325, questiontext:’Question 2’, answers:[ {
option:’A’, optionid:384729, optiontext:’Option A’, correct:false,
answered:false },{ option:’B’, optionid:384729, optiontext:’Option
B’, correct:false, answered:false },{ option:’C’, optionid:384729,
optiontext:’Option C’, correct:false, answered:false },{
option:’D’, 2 optionid:384729, optiontext:’Option D’, correct:true,
answered:true }] },{ number:3, questionid:34532,
questiontext:’Question 1’, answers:[ { option:’A’, optionid:384729,
optiontext:’Option A’, correct:true, answered:true },{ option:’B’,
optionid:384729, optiontext:’Option B’, correct:false,
answered:false },{ option:’C’, optionid:384729, optiontext:’Option
C’, correct:false, answered:false },{ option:’D’, optionid:384729,
optiontext:’Option D’, correct:false, answered:false }] },{
number:4, questionid:34532, questiontext:’Question 1’, answers:[ {
option:’A’, 3 optionid:384729, optiontext:’Option A’, correct:true,
answered:true },{ option:’B’, optionid:384729, optiontext:’Option
B’, correct:false, answered:false },{ option:’C’, optionid:384729,
optiontext:’Option C’, correct:false, answered:false },{
option:’D’, optionid:384729, optiontext:’Option D’, correct:false,
answered:false }] },{ number:5, questionid:34532,
questiontext:’Question 1’, answers:[ { option:’A’, optionid:384729,
optiontext:’Option A’, correct:false, answered:false },{
option:’B’, optionid:384729, optiontext:’Option B’, correct:false,
answered:false },{ option:’C’, 4 optionid:384729,
optiontext:’Option C’, correct:false, answered:false },{
option:’D’, optionid:384729, optiontext:’Option D’, correct:true,
answered:true }] },{ number:6, questionid:34532,
questiontext:’Question 1’, answers:[ { option:’A’, optionid:384729,
optiontext:’Option A’, correct:true, answered:true },{ option:’B’,
optionid:384729, optiontext:’Option B’, correct:false,
answered:false },{ option:’C’, optionid:384729, optiontext:’Option
C’, correct:false, answered:false },{ option:’D’, optionid:384729,
optiontext:’Option D’, correct:false, answered:false }] }, 5 {
number:7, questionid:34532, questiontext:’Question 1’, answers:[ {
option:’A’, optionid:384729, optiontext:’Option A’, correct:false,
answered:true },{ option:’B’, optionid:384729, optiontext:’Option
B’, correct:false, answered:false },{ option:’C’, optionid:384729,
optiontext:’Option C’, correct:true, answered:false },{ option:’D’,
optionid:384729, optiontext:’Option D’, correct:false,
answered:false }] },{ number:8, questionid:34532,
questiontext:’Question 1’, answers:[ { option:’A’, optionid:384729,
optiontext:’Option A’, correct:false, answered:false },{
option:’B’, 6 optionid:384729, optiontext:’Option B’,
correct:false, answered:false },{ option:’C’, optionid:384729,
optiontext:’Option C’, correct:false, answered:false },{
option:’D’, optionid:384729, optiontext:’Option D’, correct:true,
answered:true }] },{ number:9, questionid:34532,
questiontext:’Question 1’, answers:[ { option:’A’, optionid:384729,
optiontext:’Option A’, correct:false, answered:false },{
option:’B’, optionid:384729, optiontext:’Option B’, correct:false,
answered:false },{ option:’C’, optionid:384729, optiontext:’Option
C’, correct:true, answered:true },{ option:’D’, 7 optionid:384729,
optiontext:’Option D’, correct:false, answered:false } ] }, {
number:10, questionid:34532, questiontext:’Question 1’, answers:[ {
option:’A’, optionid:384729, optiontext:’Option A’, correct:true,
answered:false }, { option:’B’, optionid:384729, optiontext:’Option
B’, correct:false, answered:false }, { option:’C’, optionid:384729,
optiontext:’Option C’, correct:false, answered:true }, {
option:’D’, optionid:384729, optiontext:’Option D’, correct:false,
answered:false } ] } ] })
WriteResult({ "nInserted" : 1 })
>db.mycol.aggregate([{$group : {_id : "$name", total_exam :
{$sum : 1}}}])
{ "_id" : 'Smith', "total_exam" : 1 }
Explanation:
$group operator will creates group on the basis of name fields
$sum will keep on adding 1 to the sum of all entries obtained having similar name and hence counting the number of exams given by a student.
Note:[Please comment in case of any query]
Suppose that you are given a collection of JSON documents that represent a database of multiple...
4. The exams database: The following database contains multiple choice exam questions tables Questions and On Hons). Each question has a question Tert and each one of the options has and optid, which is an integer representing options A) (optid=1), B) (optid=2), C) (optid=3), etc. as well as the text of the option. The field correct is either Oor 1 and indicates which is the correct option for that particular question. courseThe exams have numbers 1, 2, 3, etc. Each...
Problems and Exercises 1 through 9 are based on the dass scheduling
3NF relations along with some sample data shown in Figure 6-11.
Not shown in this figure are data for an ASSIGNMENT relation,
which represents a many-to-many relationship between faculty and
sections.4. Write SQL data definition commands for each of the following queries:a. How would you add an attribute, Class, to the Student
table?b. How would you remove the Registration table?c. How would you change the FacultyName field from...
3) Suppose a student is taking a multiple-choice question exam in which each answer has four choices. Assuming that she has no knowledge of the correct answers to any of the questions, she has decided on the following strategy: She will place four balls marked A, B, C, and D in a box. She randomly selects one ball for each question and replaces the ball in the box after marking the letter of the ball as the answer. If there...
Required: In the partial database given below, indicate the table name(s) that are linked with the listed tables. If more than one table is applicable, select the option that contains multiple tables. Author Table Author ID Last Name AU-1 Adams AU-2 Brown AU-3 Davis AU-4 Newport AU-5 Pham AU-6 Sviokla First Name Eric Jennifer Keith Kevin John Julia Email Eric168@yahoo.com jenifferb@gmail.com keithd@gmail.com kevinn@hotmail.com johnpham@gmail.com jsviokla@yahoo.com Phone Number (714) 833-2419 (619) 596-0012 (212) 342-5680 (301) 947-7741 (617) 645-3647 (805) 498-1688 Book...
HW4.5. Multiple-choice Test A multiple-choice test has 43 questions. Each question has 4 choices. If you guess at random on all the questions and each guess is independent from one another, what are the expected value and standard deviation of the number of correct answers on your test? 1. What is the expected value of the number of correct answers on your test? (a) 10.75 (b) 21.5 (c) 8.75 (d) 11.75 2. What is standard deviation of the number of...
The local driver’s license office has asked you to write a program that grades the written portion of the driver’s license Rules and Signals Test. The driver license test has 25 multiple choice questions. The set of answer keys is: 1.A 6.B 11.C 16.B 2 21.B 2.C 7.C 12.A 17.A 22.C 3.B 8.D 13.B 18.C 23.A 4.B 9.A 14.C 19.A 24.D 5.D 10.B 15.A 20.D 25.B First, the application displays messages to ask for the information of current candidate about...
CHAPTER 1: DATABASES AND DATABASE USERS Given the simple Doctor-Treats_Patient database schema which contains three files describing information about doctors and patients they treat as follows, answer the following questions with regards to this database. (Total for que 1 is 10 marks) Doctor (DocID: string, DName: string, DAddress: string, Numpatients: integer) Treats (DocId: string, SSN: string, illness: string, day: string, cost: real) Patient (SSN: string, PatientName: string, PAddress: string, Age:integer) Note : DocID, DName, DAddress and Numpatients...
A test consists of 25 multiple choice questions. Each question has 5 possible answers, or which only one is correct. If a student guesses on each question, find the following. a) The probability that he will guess all of them correct b)The probability that he will guess at most 15 correct. c)The probability that he will guess at least one correct. d) The mean and the standard deviation of the number of correct answers. e)Estimate the probability of the number...
Suppose you forget to study for an exam. The exam is multiple choice and has one correct answer of 4 possible choices. Suppose that the exam contains 20 questions of which you guess on every one. a. What is the probability that you get exactly 10 questions correct by guessing? b. What is the probability that you get at most 1 question correct by guessing? c. What is the probability that you get at least 1 question correct by guessing?...
You have been asked to write a program to grade several multiple-choice exams. The exam has 20 questions, each answered with a letter in the range of ‘a’ through ‘f’. The answers key is declared in the program as constant of type string. An example of answer key is “abcdefabcdefabcdefab”. Your program should work for any other answer key. The program should first ask users for the number of students to be graded. Then it should have a while loop...