0
読書のMongoDBマニュアルの集約についてaggregation
操作、私はthisを見つけた:マルチフィールド
db.orders.aggregate(
[
{ $match: { status: "A" } },
{ $group: { _id: "$cust_id", total: { $sum: "$amount" } } },
{ $sort: { total: -1 } }
],
{
explain: true
}
)
しかし、私はおよそcust_id
とphone
を集約することができますどのようにphone
という名前の別のフィールドを、持っていると仮定?
{ $group: { _id: {"$cust_id", "$phone"}, total: { $sum: "$amount" } } },
しかし、私はこの振る舞いたい
EDIT
動作しません:
SELECT SUM(amount)
FROM orders
GROUP BY cust_id, phone
をしかし、私はこれを持って、私は次のように試してみた
エラー(私はMongoChef Iによってスクリーンショットを添付する必要があります)テキストのエラーすることはできません。
*は問題ありません。あなたは何を期待していますか? –
可能な複製:http://stackoverflow.com/questions/22932364/mongodb-group-values-by-multiple-fields – RudyVerboven