我已经使用聚合在 mongodb 中编写了一个查询,该查询工作正常,但不知怎的,它在我的 python 代码中使用 pymongo 时无法正常工作。请指教如何纠正。
蒙戈查询:
db.flights.aggregate([
{ $match: { origin:"ATL", dest:"BOS",dayofweek: 3} },
{ $group: {
_id: {
origin:"$origin",
destination: "$dest"
},
Failure: { $sum: { $cond : [{ $eq : ["$cancelled", 1]}, 1, 0]} },
Success: { $sum: { $cond : [{ $eq : ["$cancelled", 0]}, 1, 0]} },
Total: { $sum: 1 }
} },
{$project:{Failure:1,Success:1, Total:1, FailPercent: { $divide: [ "$Failure", "$Total" ]}}},
{ $sort: { "_id.origin": 1, "_id.destination": 1 } }
])
Run Code Online (Sandbox Code Playgroud)
在Python代码中: …