<code>$elemMatch</code> operator query

Report a typo

Suppose you have a collection named users that contains documents with an array field orders that lists the orders made by each user. Each order document in the orders array has a status field and a total field.

{
  "_id": ObjectId("61efad4e6ebd9a4a748b4c4f"),
  "name": "Alice",
  "orders": [
    {
      "status": "completed",
      "total": 50
    },
    {
      "status": "pending",
      "total": 150
    }
  ]
},
{
  "_id": ObjectId("61efad4e6ebd9a4a748b4c50"),
  "name": "Bob",
  "orders": [
    {
      "status": "completed",
      "total": 75
    },
    {
      "status": "pending",
      "total": 90
    }
  ]
},
{
  "_id": ObjectId("61efad4e6ebd9a4a748b4c51"),
  "name": "Charlie",
  "orders": [
    {
      "status": "completed",
      "total": 120
    },
    {
      "status": "completed",
      "total": 80
    }
  ]
}

Write a MongoDB query that returns all users who have an order with a "pending" status and a total of greater than 100.

Enter a short text
___

Create a free account to access the full topic