aggregation framework - need expert opinion - mongodb query -


i need expert evaluation concerning created queries. there collection "myresults" documents of such view:

{     "_id": 0,     "name": "aimee zank",     "scores": [{     "type": "exam",     "score": 1.463179736705023     }, {     "type": "quiz",     "score": 11.78273309957772     }, {     "type": "homework",     "score": 6.676176060654615     }, {     "type": "homework",     "score": 35.8740349954354     }] } 

task:

  1. to write query searching students, have "score" > 93 , < 95 in "type".

  2. to write aggregate query in order select students, have "exam" result > 90.

  3. to add field "accepted" value = true student dan doe.

solution:

1.

db.myresults.find({ $or: [{     $and: [{         "scores.type": "exam"     }, {         "scores.score": {             $gt: 93         }     }, {         "scores.score": {             $lt: 95         }     }] }, {     $and: [{         "scores.type": "quiz"     }, {         "scores.score": {             $gt: 93         }     }, {         "scores.score": {             $lt: 95         }     }] }, {     $and: [{         "scores.type": "homework"     }, {         "scores.score": {             $gt: 93         }     }, {         "scores.score": {             $lt: 95         }     }] }] }) 

2.

db.myresults.aggregate([{     $unwind: "$scores" }, {     $match: {     $and: [{         type: "exam"     }, {         score: {             $gt: 90         }     }]     } }]) 
  1. db.myresults.update({name: "dan doe"}, {$set: {accepted: true}})

p.s. "accepted" added in third task... when selecting turns out dan doe two... , "accepted" written in first...???


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -