pymongo 聚合不允许解释选项

pymongo aggregate don't allow explain option

我成功了运行:

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)