db.transaction.aggregate(
[
{
"$match":
{"AMOUNT":{"$ne":null}}
},
{
"$group":
{"_id":{}}
},
{
"$addFields":
{AMOUNT:{$toDouble:["$AMOUNT"]}}
},
{
"$project":
{"AMOUNT":{"$gt": 10000}}
}
]
);
Trying to fetch amount from the collection which is greater than 10000, as I’m working in MongoDB so data is in string format, so I’m using aggregation with $addFields parameter to change the string into the double and then apply the $gt function.
Tried multiple way by arranging query in group but not able to solve it.
Please help
2
Answers
You can use same $expr in aggregation function inside $match
Per @Buzz Moschetti suggestion:
Or:
See how it works on the playground example