我尝试了一百万次使用的Mongo。我的要求非常慢。
您有什么想法来优化它吗?
db.financial_transaction.runCommand({
"aggregate": "financial_transaction",
"pipeline": [ {
"$match": {
"transaction_type": { "$in": [ 1, 2 ] },
"created_at": { "$gte": new ISODate("2016-03-13T00:00:00+01:00"), "$lte": new ISODate("2017-12-13T23:59:00+01:00") },
"type": { "$in": [ "A", "C", "E" ] },
"sid": { "$in": [ 1, 3, 7, 9, 11, 13 ] },
"context": { "$in": [ "CL", "RE" ] } }
}, {
"$group": { "_id": { "paymentType": "$payment_type",
"paymentMethod": "$payment_method",
"responseCode": "$response_code",
"reasonCode": "$reason_code"
},
"count": { "$sum": 1 }, "total_amount": { "$sum": "$requested_amount" } } }, { "$sort": { "count": -1 } } ]
});
索引:
_id_
idx_context
idx_payment_method
idx_response_code
idx_reason_code
idx_created_at
idx_transaction_type
idc_payment_method_created_at_transaction_type_origin_auth_system
idx_created_at_context_transaction_type
idx_updated_at
我对解释结果提出了要点:https://gist.github.com/sanchobouillant/bd59403242ebb1ec45582dff74b457a2