gpt4 book ai didi

javascript - Mongodb - 错误查询 : BadValue unknown top level operator: $gte

转载 作者:IT老高 更新时间:2023-10-28 13:13:40 30 4
gpt4 key购买 nike

这个查询有什么问题?我试图在 mongodb 服务器上运行它并收到如下错误 - “异常:错误查询:BadValue 未知顶级运算符:$gte”。谁能告诉我这有什么问题吗?

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

样本数据:

        {
"_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"
}

最佳答案

你做错了。应该是:

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

这是指定“范围”查询的正确方法,其中实际条件是“和”,因此是“在”指定的操作数之间。

关于javascript - Mongodb - 错误查询 : BadValue unknown top level operator: $gte,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26755391/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com