pymongo aggregate don't allow explain option

試著忘記壹切 提交于 2020-01-02 06:47:05

问题


I succesfully run:

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

Now when I try:

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

it fails saying:

pymongo.errors.ConfigurationError: The explain option is not supported. Use Database.command instead.

Thus I try so as to add the needed option:

result = mydb.command('aggregate', 'mycol', my_pipeline, {'explain':True})

but it fails saying:

pymongo.errors.OperationFailure: 'pipeline' option must be specified as an array

What is wrong?

Thanks for any advice.

Christian


回答1:


Pass your pipeline using the "pipeline" keyword argument to "command":

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

For example:

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


来源:https://stackoverflow.com/questions/43677161/pymongo-aggregate-dont-allow-explain-option

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!