我在 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"}
我相信您正在尝试按 returnflag 和 linestatus 分组
这至少应该可以解决您的错误。
关于MongoDB $group 不支持包含式表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36321062/
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
在我的应用程序中,我需要能够找到所有数字子字符串,然后扫描每个子字符串,找到第一个匹配范围(例如5到15之间)的子字符串,并将该实例替换为另一个字符串“X”。我的测试字符串s="1foo100bar10gee1"我的初始模式是1个或多个数字的任何字符串,例如,re=Regexp.new(/\d+/)matches=s.scan(re)给出["1","100","10","1"]如果我想用“X”替换第N个匹配项,并且只替换第N个匹配项,我该怎么做?例如,如果我想替换第三个匹配项“10”(匹配项[2]),我不能只说s[matches[2]]="X"因为它做了两次替换“1fooX0barXg
我有一个包含多个键的散列和一个字符串,该字符串不包含散列中的任何键或包含一个键。h={"k1"=>"v1","k2"=>"v2","k3"=>"v3"}s="thisisanexamplestringthatmightoccurwithakeysomewhereinthestringk1(withspecialcharacterslike(^&*$#@!^&&*))"检查s是否包含h中的任何键的最佳方法是什么,如果包含,则返回它包含的键的值?例如,对于上面的h和s的例子,输出应该是v1。编辑:只有字符串是用户定义的。哈希将始终相同。 最佳答案
@raw_array[i]=~/[\W]/非常简单的正则表达式。当我用一些非拉丁字母(具体来说是俄语)尝试时,条件是错误的。我能用它做什么? 最佳答案 @raw_array[i]=~/[\p{L}]/使用西里尔字符进行测试。引用:http://www.regular-expressions.info/unicode.html#prop 关于ruby-正则表达式将非英文字母匹配为非单词字符,我们在StackOverflow上找到一个类似的问题: https://
我需要一个非常简单的字符串验证器来显示第一个符号与所需格式不对应的位置。我想使用正则表达式,但在这种情况下,我必须找到与表达式相对应的字符串停止的位置,但我找不到可以做到这一点的方法。(这一定是一种相当简单的方法……也许没有?)例如,如果我有正则表达式:/^Q+E+R+$/带字符串:"QQQQEEE2ER"期望的结果应该是7 最佳答案 一个想法:你可以做的是标记你的模式并用可选的嵌套捕获组编写它:^(Q+(E+(R+($)?)?)?)?然后你只需要计算你获得的捕获组的数量就可以知道正则表达式引擎在模式中停止的位置,你可以确定匹配结束
我的Gallery模型中有以下查询:media_items.includes(:photo,:video).rank(:position_in_gallery)我的图库模型有_许多媒体项,每个都有一个照片或视频关联。到目前为止,一切正常。它返回所有media_items包括它们的photo或video关联,由media_item的position_in_gallery属性排序。但是我现在需要将此查询返回的照片限制为仅具有is_processing属性的照片,即nil。是否可以进行相同的查询,但条件是返回的照片等同于:.where(photo:'photo.is_processingIS
我想从then子句中访问case语句表达式,即food="cheese"casefoodwhen"dip"then"carrotsticks"when"cheese"then"#{expr}crackers"else"mayo"end在这种情况下,expr是食物的当前值(value)。在这种情况下,我知道,我可以简单地访问变量food,但是在某些情况下,该值可能无法再访问(array.shift等)。除了将expr移出到局部变量然后访问它之外,是否有直接访问caseexpr值的方法?罗亚附注我知道这个具体示例很简单,只是一个示例场景。 最佳答案
这是一个例子:s="abcd+subtext@example.com"s.match(/+[^@]*/)Result=>"+subtext"问题是,我不想在其中包含“+”。我希望结果是“潜台词”,没有+ 最佳答案 您可以在正则表达式中使用括号来创建匹配组:s="abcd+subtext@example.com"s=~/\+([^@]*)/&&$1=>"subtext" 关于ruby-正则表达式-排除一个字符,我们在StackOverflow上找到一个类似的问题:
-if!request.path_info.include?'A'%{:id=>'A'}"Text"-else"Text"“文本”写了两次。我怎样才能只写一次并同时检查path_info是否包含“A”? 最佳答案 有两种方法可以做到这一点。使用部分,或使用content_forblock:如果“文本”较长,或者是一个重要的子树,您可以将其提取到一个部分。这会使您的代码变干一点。在给出的示例中,这似乎有点矫枉过正。在这种情况下更好的方法是使用content_forblock,如下所示:-if!request.path_info.inc
我们有一个字符串:“”这个正则表达式://i如何从当前字符串中获取所有匹配项? 最佳答案 "".scan(//)参见scan在ruby-docs上 关于ruby-如何遍历Ruby中所有正则表达式匹配的字符串?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/6857852/