Transactions elemMatch not retrieve what is expected

Hello.
On LESSON 4: QUERYING ON ARRAY ELEMENTS IN MONGODB
At Lab: Querying on Array Elements in MongoDB

db.transactions.find({
transactions: {
$elemMatch: { amount: { $lte: 4500 }, transaction_code: “sell” },
},
})

Does not retrieve what is expected.
Any ideas?
Regards
Jorge

Please share the documents you are expecting to retrieve.

1 - you are connected to the wrong server
2 - you are using the wrong database
3 - there is no collection named transactions
4 - there is no document that has an array named transactions that matches

Hi Jorge,

The $elemMatch operator will return any document for which at least 1 array item meets the query. I went through the lab, and it is indeed what is returned so it seems to work as expected.

If you are seeing something different or some errors, please open a ticket with the MongoDB University Team by sending an email to learn@mongodb.com.

Thank you,

Davenson Lombard

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.