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

后端 未结 3 1059
旧时难觅i
旧时难觅i 2021-01-01 15:30

What is wrong with this query? I tried to run it on mongodb server and received an error as following - \"exception: bad query: BadValue unknown top level operator: $gte\".

3条回答
  •  情书的邮戳
    2021-01-01 16:29

    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.

提交回复
热议问题