Mongodb - bad query: BadValue unknown top level operator: $gte
Since MongoDB version 3.6, you may use $expr to use aggregate expressions within a query. So the query can be rewritten into:
db.scores.aggregate([
{
$match: {
$expr: {
$or: [
{ $gte: ["$score", 30] },
{ $lte: ["$score", 60] }
]
}
}
},
{
$group: {
_id: "$gamer",
games: { $sum: 1 }
}
}
]);
You did this wrong. Should be:
db.scores.aggregate([
{ "$match": {
"score": { "$gte": 30, "$lte": 60 }
}},
{ "$group": {
"_id": "$gamer",
"games": { "$sum": 1 }
}}
])
Which is the proper way to specify a "range" query where the actual conditions are "and" and therefore "between" the operands specified.