需要专家意见 - mongodb查询

时间:2015-06-01 07:39:30

标签: mongodb aggregation-framework

我需要有关已创建查询的专家评估。集合"myresults"包含此类视图的文档:

{
    "_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
    }]
}

任务:

  1. 编写查询以搜索所有有"得分" > 93和< 95 in any" type"。

  2. 编写汇总查询以选择具有"考试"结果> 90。

  3. 添加字段"已接受"学生Dan Doe value = true

  4. 解决方案:

    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}})
    2. P.S。 "接受"在第三个任务中成功添加......但是当选择它时,Dan Doe就是两个......并且接受了#34;只写在第一...... ???

0 个答案:

没有答案
相关问题