I have a collection with this data:
[
{
_id: "123",
number: 10,
users: [
{
amount: 20
}
]
},
{
_id: "456",
number: 20,
users: [
{
amount: 10
}
]
}
]
I need to find documents where users[0].amount is greater than or equal to number. I have the following Mongoose query:
Model.aggregate([
{
$match: {
$expr: {
$and: [
{ $gte: ["$users.0.amount", "$number"] },
...
]
}
}
}
]);
However, this doesn't seem to be filtering the documents properly. I'm assuming $users.0.amount isn't the correct syntax. How can I fix this?