I am working with a dataset which looks something like:
{
"class_id" : 5,
"scores" : [
{
"type" : "exam",
"score" : 88.22950674232497
},
{...}
]
}
I have the following aggregate query:
db.grades.aggregate([
{ $project:
{_id: 0, class_id: 1, scores: {$filter: { input: "$scores", as: "score", cond: {$or: [{"score.type" : "homework"}, {"score.type" : "exam"}] }}}}
}
])
My error is: "dotted field names are only allowed at the top level". I have also tried "$score.type" and "$$score.type" in which case I get the error '$score.type' is an invalid operator.
Any idea's how I can work around this?
