2016-04-04 8 views
1

$マッチ集約式の内部で許可されていません$のMongoDB:「私はこのエラーを得た

」$マッチ集約式Iが実行

の内部で許可されていないところ$次のクエリ

var query = { $and : [ 
    {"order.orderstatus" : "F"}, 
    {"partsupp.supplier.nation.name" : { $regex : '^SAUDI ARABIA'} }, 
    {$where : "this.receiptdate > this.commitdate"} 
]}; 

var multisupp = { 
    $where : function() { 
     return db.lineitems.findOne({ $and : [ 
      { "order.orderkey" : this.order.orderkey }, 
      { "partsupp.supplier.suppkey" : { "$ne" : this.partsupp.supplier.suppkey} } 
     ]}) != null; 
    } 
}; 

var onlyfail = { 
    $where : function() { 
     return db.lineitems.findOne({ $and : [ 
      { "order.orderkey" : this.order.orderkey }, 
      { "partsupp.supplier.suppkey" : { "$ne" : this.partsupp.supplier.suppkey} }, 
      { $where : "this.receiptdate > this.commitdate" } 
      ]}) == null; 
    } 
}; 

res = db.lineitems.aggregate([ 
    { $match : query}, 
    { $match : multisupp}, 
    { $match : onlyfail}, 
    { $project : { 
     _id : 0, 
     s_name : "$partsupp.supplier.name" } }, 
    { $group : { 
     _id : "$s_name", 
     numwait : { $sum : 1} } }, 
    { $sort : { numwait : -1, _id : 1} } 
]); 

そしてこれはコレクションスキーマです。 (このコレクションは、巨大なスキーマを持っていますが、私はその問題のために重要ではないと思います)

{ 
    "linenumber": 6, 
    "quantity": 17, 
    "extendedprice": 21085.78, 
    "discount": 0.08, 
    "tax": 0.01, 
    "returnflag": "R", 
    "linestatus": "F", 
    "shipdate": "Wed Oct 20 00:00:00 BST 1993", 
    "commitdate": "Thu Dec 09 00:00:00 GMT 1993", 
    "receiptdate": "Sun Nov 14 00:00:00 GMT 1993", 
    "shipinstruct": "COLLECT COD", 
    "shipmode": "REG AIR", 
    "comment": "ns. carefully regular asym", 
    "order": { 
     "orderkey": 535110, 
     "orderstatus": "F", 
     "totalprice": 200883.33, 
     "orderdate": "Fri Oct 01 00:00:00 BST 1993", 
     "orderpriority": "1-URGENT", 
     "clerk": "Clerk#000000110", 
     "shippriority": 0, 
     "comment": "furiously against the regular ideas; quickly regular dep", 
     "order": { 
      "custkey": 6464, 
      "name": "Customer#000006464", 
      "address": "eF9E6ScHCw9,z8nF0py9 ySlB0 iHTIEEZRWl6H", 
      "phone": "11-870-572-9943", 
      "acctbal": 5468.53, 
      "mktsegment": "FURNITURE", 
      "comment": "telets could are quickly regular packages. fluffily iro", 
      "customer": { 
       "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" 
       } 
      } 
     } 
    }, 
"partsupp": { 
    "availqty": 9067, 
    "supplycost": 441.56, 
    "comment": ". bold instructions are carefully blithely final foxes. slyly unusual ideas wake slowly aroun", 
    "part": { 
     "partkey": 340, 
     "name": "sienna purple lawn coral navy", 
     "mfgr": "Manufacturer#2", 
     "brand": "Brand#23", 
     "type": "STANDARD BRUSHED TIN", 
     "size": 3, 
     "container": "JUMBO BOX", 
     "retailprice": 1240.34, 
     "comment": "l ideas wake. quic" 
    }, 
    "supplier": { 
     "suppkey": 91, 
     "name": "Supplier#000000091", 
     "address": "YV45D7TkfdQanOOZ7q9QxkyGUapU1oOWU6q3", 
     "phone": "13-604-986-9056", 
     "acctbal": 6255.87, 
     "comment": "nstructions use carefully according to the special packages: quickly silent th", 
     "nation": { 
      "nationkey": 3, 
      "name": "CANADA", 
      "comment": "eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold", 
      "region": { 
       "regionkey": "1", 
       "name": "AMERICA", 
       "comment": "hs use ironic, even requests. s" 
      } 
     } 
    } 
} 

誰かがそれを解決するために私を助けることができますか?ありがとうございました。

+3

ここで説明するエラー以外にも、ここでは「大きな」問題がかなりあります。特に、サブクエリも実行しようとしています。これはMongoDBがやっていないものです。 '$ where'だけでなく残りのものも簡単に解決できますが、ここで何をしようとしているのかははっきりしていません。おそらく、それは* "他のラインアイテムはこれらの条件を満たす必要があります" *の行に沿ったものかもしれませんが、あなたは本当にすべてのロジックを説明していないので(そしてあなたの現在のアプローチは間違っています) –

+1

'{$ where:" this.receiptdate> This.commitdate "}'の代わりに、 '$ gt'を次のように使用してください:' {"this.receiptdate:{$ gt:this.com}}}' –

+0

@SiddharthAjmera '$ gt'のクエリ式で' this'(これはすでにドキュメントにあるデータを参照する方法です)を使うことはできません。 –

答えて

1

エラーが示すように、集約クエリ内に$whereを含めることはできません。

var query = { $and : [ 
    {"order.orderstatus" : "F"}, 
    {"partsupp.supplier.nation.name" : { $regex : '^SAUDI ARABIA'} }, 
    {receiptdate : { $gt : commitdate} 
]}; 
関連する問題