如何在Python中翻译Mongodb聚合命令?

如何在Python中翻译Mongodb聚合命令?,python,mongodb,aggregation-framework,Python,Mongodb,Aggregation Framework,我正在mongo CLI中运行以下命令,以识别集合中具有相同创建日期的2个或多个文档 db.collection_name.aggregate({$group: { _id: "$date", count: { $sum: 1 }, docs:{ $push : "$_id" }}}, { $match: { count: { $gt: 1 } } }) 然而,当我试图从一个包含以下行的Python脚本中运行它时,我得到了错误 collection = db[collections_name]

我正在mongo CLI中运行以下命令,以识别集合中具有相同创建日期的2个或多个文档

db.collection_name.aggregate({$group: { _id: "$date", count: { $sum: 1 }, docs:{ $push : "$_id" }}}, { $match: { count: { $gt: 1 } } })
然而,当我试图从一个包含以下行的Python脚本中运行它时,我得到了错误

collection = db[collections_name]
collection.aggregate({"$group": { '_id': "$date", 'count': { "$sum": 1 }, 'docs':{ "$push" : "$_id" }}}, { "$match": { 'count': { "$gt": 1 } } })

无法理解我做错了什么。任何帮助都将不胜感激。谢谢

管道操作必须作为python列表传入

collection.aggregate([{"$group": { '_id': "$date", 'count': { "$sum": 1 }, 'docs':{ "$push" : "$_id" }}}, { "$match": { 'count': { "$gt": 1 } } }])

. 这会有帮助的。您得到的错误是什么?