Multiple array query operators requet

Report a typo

Suppose the students collection contains documents with the following structure:

{
  "_id": ObjectId("123456789012"),
  "name": "John Doe",
  "age": 18,
  "grades": [
    { "subject": "Math", "score": 85 },
    { "subject": "Science", "score": 90 },
    { "subject": "English", "score": 80 }
  ]
}
{
  "_id": ObjectId("123456789013"),
  "name": "Bob Smith",
  "age": 19,
  "grades": [
    { "subject": "Math", "score": 70 },
    { "subject": "Science", "score": 84 },
    { "subject": "English", "score": 75 },
  ]
}
{
  "_id": ObjectId("123456789014"),
  "name": "Jane Johnson",
  "age": 20,
  "grades": [
    { "subject": "Math", "score": 90 },
    { "subject": "Science", "score": 80 },
    { "subject": "English", "score": 95 },
    { "subject": "History", "score": 80 }
  ]
}

This time we want to find all students who have three grades and one of those grades is in the "Science" subject with a score greater than or equal to 85.

We have the following query:

db.students.find({
  "grades": {
    "$operator": 3,
    "$operator": {
      "subject": "Science",
      "score": { "$gte": 85 }
    }
  }
})

Write down the correct operators instead of $operator that would make the query work to return "John Doe".

(separate operator names with the comma with no space)

Enter a short text
___

Create a free account to access the full topic