我成功运行:

result = my_col.aggregate(my_pipeline, allowDiskUse=True)

现在当我尝试:
result = my_col.aggregate(my_pipeline, allowDiskUse=True, explain=True)

它没有说:
pymongo.errors.ConfigurationError: The explain option is not supported. Use Database.command instead.

因此,我尝试添加所需的选项:
result = mydb.command('aggregate', 'mycol', my_pipeline, {'explain':True})

但它没有说:
pymongo.errors.OperationFailure: 'pipeline' option must be specified as an array

怎么了?

感谢您的任何建议。

基督教

最佳答案

使用“pipeline”关键字参数将您的管道传递给“command”:

db.command('aggregate', 'mycol', pipeline=my_pipeline, explain=True)

例如:
db.command('aggregate', 'mycol', pipeline=[{'$project': {'name': '$field'}}], explain=True)

关于mongodb - pymongo 聚合不允许解释选项,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43677161/

10-16 03:49
查看更多