In MongoDB how to query an embeded array which has same key name

25 Views Asked by At
{
    '_id': 103, 
    'name': 'Fleta Duplantis', 
    'scores': [
        {'score': 84.37799696030743, 'type': 'exam'}, 
        {'score': 15.95792143439528, 'type': 'quiz'}, 
        {'score': 77.80745176713172, 'type': 'homework'}
    ]
}

I have 200 documents in this, I need to calculate the average for each test type and also need to check if the score is above 40 in each category

db.Stumarks.find({'scores':{'$elemMatch':{'type':'exam','score':{'$gte':40}}}})

I tried this, i am getting it for one category. but I couldn't store this result in a separate collection using the $out command

0

There are 0 best solutions below