2016-03-30 12 views
2

Ich habe „errmsg“: „$ group nicht Einbeziehung Stil Ausdrücke unterstützen“ mit der folgenden Abfrage in mongoDB

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}} 
); 

Es ist eine Probe ein Dokument:

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

} ich weiß nicht, was das Problem ist. Ich habe 150k Dokumente wie das und ich möchte diese Ergebnisse erhalten, aber ich bekomme diesen Fehler.

+0

Bitte fügen Sie auch MongoDB-Beispieldokumente hinzu – Saleem

+0

Ein Beispiel hinzugefügt @Saleem – duknust

+0

siehe meinen Beitrag unten. es sollte Fehler mindestens beheben – Saleem

Antwort

8

Ihr Problem liegt in

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

Here "returnfalg": 1 nicht unterstützt wird. es ist gültig in $project nicht in $group Wenn Sie Composite-Schlüssel erstellen möchten, versuchen

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

Ich glaube, Ihr von returnflag und linestatus zu Gruppe versuchen

Dies sollte Ihr Fehler zumindest beheben.

0

Ich habe bereits die Antwort bekommen. Ich muss diese folgenden Code ändern

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

zu

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

Ameise es funktioniert.