You can get the original collection object implemented with the pymongo driver using the ._get_collection () method in the class.
Class._get_collection().aggregate([
{ '$group': {
'_id': {
'year': { '$year': '$utc_timestamp' },
'month': { '$month': '$utc_timestamp' },
'day': { '$dayOfMonth': '$utc_timestamp' },
},
'defects': {
'$sum': { '$cond': [
{ '$eq': [ '$status', 'defect' ] },
1,
0
]}
},
'totalCount': { '$sum': 1 }
}},
{ '$project': {
'defect_rate': {
'$cond': [
{ '$eq': [ '$defects', 0 ] },
0,
{ '$divide': [ '$defects', '$totalCount' ] }
]
}
}}
])
source
share