Student achievement data operation based on MongoDB

Keywords: Database MongoDB

MongoDB detailed syntax thinking map click here to download

       With the diversified development of educational reform, school assessment methods are becoming more and more diverse. This also causes the results of the traditional course grade database table to no longer meet the setting of multiple assessment objectives.

The school plans to introduce noSQL database to store course assessment results and other information. MongoDB, as a distributed noSQL database, is selected by the school as the next generation of course grade database software.

In order to test whether MongoDB can meet the management of course score data, you have received the following tasks:

  1. Create a MongoDB database with the name "DB your student number"“
  2. Create a MongoDB database collection with the name "your name Pinyin initials"“
  3. Import test data: the test data has been put into a jsonArray file (see the attachment). Use mongoimport or write a load_scores.js script to import the data.
  4. Insert a "distributed database course principle and application" score record with your own student number, class, instructor and course name. The record data structure should be the same as other entries.
  5. Query the final scores of students of big data 2019 distributed database course
  6. Query the homework 1 scores of students in the network operating system course taught by teacher Zhang San
  7. Query the student number of students who fail the midterm examination of distributed database course
  8. Increase the total score of all girls (gender=0) by 5 points. If the score exceeds 100, it will be set to 100
  9. Delete student records without usual homework scores
  10. The average total evaluation scores of "network operating system" courses are counted according to the teaching teachers

Answer requirements:

  1. Use MongoShell to complete the operations required in the question, and fill in the command and the screenshot of the result of executing the command on the answer page;

preparation:

Create database: use db123;

Create collection: db.createCollection("wxw");

Import data:

Data set click here to download
 

Var doc=[{},......,{}]

db.wxw.insert(doc);

4. Insert a score record of "distributed database course principle and application" using your own student number, class, instructor and course name. The record data structure should be the same as other items.

var docs = {

    "course": "Principle and application of Distributed Database Course",

    "teacher": "Little cold",

    "sno": "123",

    "gender": 1,

    "major": "big data",

    "grade": 2019,

    "Usual operation": {

        "Assignment 1": 95,

        "Assignment 2": 80

    },

    "Mid term": 100,

    "End of term": 90,

    "General comment": 93

}


db.wxw.insertOne(docs);

Find whether the insertion was successful: db.wxw.find({"sno": "123"})

5. Query the final scores of students of big data 2019 distributed database course

db.wxw.find({"major": "big data",'grade':2018,"course":'Principle and application of distributed database'},{'End of term':1})

6. Check the homework 1 scores of students in the network operating system course taught by teacher Zhang San

var query criteria = {'teacher':'Zhang San','course':'Network operating system'};

var Return field = {'Usual operation.Assignment 1':1};

db.wxw.find(query criteria, Return field);

7. Query the student number of students who fail the midterm examination of distributed database course

var Step 1 = {$match:{'course':'Principle and application of distributed database','Mid term':{$lt:60}}}

var Step 2 ={$project:{_id:0,sno:1}}

var The Conduit=[Step 1,Step 2]

db.wxw.aggregate(The Conduit)

8. Increase the total score of all girls (gender=0) by 5 points. If the score exceeds 100, it will be set to 100

query1 = {"gender":"0"}

update1 = {$inc:{"General comment":5}}

option1 = {}

db.wxw.updateMany(query1, update1, option1)

If the total score exceeds 100, it is automatically set to 100

var querys={'General comment':{$gt:100}}}

var updates={$set:{'General comment':100}};

var options={multi:1};

db.wxw.update(querys, updates, options);

Check again whether there are abnormal results, No

db.wxw.find({'general comment': {$gt:100})

9. Delete student records without usual homework scores

Find the record data: db.wxw.find({"normal job": null});

Delete the data record: db.wxw.remove({"normal job": null});

View again: db.wxw.find({"normal job": null});

10. Count the average total score of "network operating system" course according to the instructor

var query criteria = {'course':'Network operating system'}

var Step 1 = {$match:query criteria} 

var Step 2 = {$group:{_id:'$teacher', Average total score:{$avg:'$General comment'}}}

var rename Id field = {$project:{_id:0,'teacher':'$_id','Network operating system':'$Average total score'}}

var The Conduit = [Step 1,Step 2]

db.wxw.aggregate(The Conduit)

Every word

110 110 110

Posted by SheetWise on Sat, 23 Oct 2021 14:11:59 -0700