gpt4 book ai didi

MongoDB $group 不支持包含式表达式

转载 作者:可可西里 更新时间:2023-11-01 09:56:28 25 4
gpt4 key购买 nike

我在 mongoDB 中使用以下查询得到 "errmsg": "$group does not support inclusion-style expressions"

db.lineitems.aggregate(
{ $match : { "shipdate" : { $lte: 19980801 }} },
{ $group : {
_id : { "returnflag" :1, "linestatus" : 1},
sum_qty : { $sum : "$quantity"},
sum_base_price : { $sum : "$extendedprice"},
sum_disc_price : { $sum : { $multiply : [ "$extendedprice",
{ $subtract : [1, "$discount"]}] }},
sum_charge : { $sum : {$multiply : [ "$extendedprice",
{ $subtract : [1, "$discount"]}, {$add : [1, "$tax"]}] }},
avg_qty : { $avg : "$quantity"},
avg_price : { $avg : "$extendedprice"},
avg_disc : { $avg : "$discount"},
count_order : { $sum : 1}
} },
{ $sort : {"_id.returnflag" : 1, "_id.linestatus" : 1}}
);

有一个文档样本:

{
"linenumber": 1,
"quantity": 41,
"extendedprice": 45682.2,
"discount": 0.02,
"tax": 0.08,
"returnflag": "N",
"linestatus": "O",
"shipdate": "Mon Jul 01 00:00:00 BST 1996",
"commitdate": "Sat Jul 20 00:00:00 BST 1996",
"receiptdate": "Fri Jul 12 00:00:00 BST 1996",
"shipinstruct": "TAKE BACK RETURN",
"shipmode": "SHIP",
"comment": "s. regular requ",
"order": {
"orderkey": 535111,
"orderstatus": "O",
"totalprice": 48350.03,
"orderdate": "Thu May 02 00:00:00 BST 1996",
"orderpriority": "3-MEDIUM",
"clerk": "Clerk#000000665",
"shippriority": 0,
"comment": "fluffily regular requests. f",
"order": {
"custkey": 10711,
"name": "Customer#000010711",
"address": "e3VJ63sxe8qAaKt 8 4daV0IE3CA9",
"phone": "14-529-725-9738",
"acctbal": 5983.81,
"mktsegment": "BUILDING",
"comment": "onic, stealthy ideas haggle carefully across the furi",
"customer": {
"nationkey": 4,
"name": "EGYPT",
"comment": "y above the carefully unusual theodolites. final dugouts are quickly across the furiously regular d",
"region": {
"regionkey": 4,
"name": "MIDDLE EAST",
"comment": "uickly special accounts cajole carefully blithely close requests. carefully final asymptotes haggle furiousl"
}
}
}
},
"partsupp": {
"availqty": 2155,
"supplycost": 123.82,
"comment": "arefully along the idly even accounts. asymptotes beside the slyly regular deposits boost since the busily unusual excus",
"part": {
"partkey": 10204,
"name": "rosy chiffon blush burlywood white",
"mfgr": "Manufacturer#5",
"brand": "Brand#55",
"type": "LARGE PLATED TIN",
"size": 23,
"container": "JUMBO PACK",
"retailprice": 1114.2,
"comment": " ironic ideas use care"
},
"supplier": {
"suppkey": 985,
"name": "Supplier#000000985",
"address": "kzI8mk3jN9F67EStJ 8dlpx 6GwZYwzXPFOKJ5R",
"phone": "11-131-656-2612",
"acctbal": 3524.1,
"comment": "ut the furiously final deposits integrate according to th",
"nation": {
"nationkey": 1,
"name": "ARGENTINA",
"comment": "al foxes promise slyly according to the regular accounts. bold requests alon",
"region": {
"regionkey": "1",
"name": "AMERICA",
"comment": "hs use ironic, even requests. s"
}
}
}
}

}我不知道是什么问题。我有 150k 份这样的文件,我想得到这个结果,但我收到了这个错误。

最佳答案

你的问题出在

{ $group : {
_id : { "returnflag" :1, "linestatus" : 1}, <---

此处不支持“returnfalg”:1。它在 $project 中有效 但在 $group 中有效 如果您想创建组合键,请尝试

_id : { "returnflag" :"$returnflag", "linestatus" : "$linestatus"}

我相信您正在尝试按 returnflaglinestatus 分组

这至少应该可以解决您的错误。

关于MongoDB $group 不支持包含式表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36321062/

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