Mongodb - bad query: unknown top-level operator BadValue: $ gte

What happened to this request? I tried to run it on the mongodb server and received the error message: "exception: bad query: unknown top-level operator BadValue: $ gte". Can someone tell me what's wrong with him, please?

db.scores.aggregate([ { $match: { $or: [ { $gte: [ "$score", 30 ] }, { $lte: [ "$score", 60 ] } ] } }, { $group: { _id: "$gamer", games: { $sum: 1 } } } ]) 

sample data:

  { "_id" : "545665cef9c60c133d2bce72", "score" : 85, "gamer" : "Latern" } /* 1 */ { "_id" : "545665cef9c60c133d2bce73", "score" : 10, "gamer" : "BADA55" } /* 2 */ { "_id" : "545665cef9c60c133d2bce74", "score" : 62, "gamer" : "BADA55" } /* 3 */ { "_id" : "545665cef9c60c133d2bce75", "score" : 78, "gamer" : "l00ser" } /* 4 */ { "_id" : "545665cef9c60c133d2bce76", "score" : 4, "gamer" : "l00ser" } /* 5 */ { "_id" : "545665cef9c60c133d2bce77", "score" : 55, "gamer" : "FunnyCat" } 
+6
source share
1 answer

You did it wrong. Must be:

 db.scores.aggregate([ { "$match": { "score": { "$gte": 30, "$lte": 60 } }}, { "$group": { "_id": "$gamer", "games": { "$sum": 1 } }} ]) 

How can you specify the query "range", where the actual conditions are "and" and, therefore, "between" the specified operands.

+8
source

Source: https://habr.com/ru/post/977763/


All Articles