Chr*_*ult 4 mongodb explain pymongo aggregation-framework
我成功运行:
result = my_col.aggregate(my_pipeline, allowDiskUse=True)
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试:
result = my_col.aggregate(my_pipeline, allowDiskUse=True, explain=True)
Run Code Online (Sandbox Code Playgroud)
它没有说:
pymongo.errors.ConfigurationError: The explain option is not supported. Use Database.command instead.
Run Code Online (Sandbox Code Playgroud)
因此,我尝试添加所需的选项:
result = mydb.command('aggregate', 'mycol', my_pipeline, {'explain':True})
Run Code Online (Sandbox Code Playgroud)
但失败说:
pymongo.errors.OperationFailure: 'pipeline' option must be specified as an array
Run Code Online (Sandbox Code Playgroud)
怎么了?
感谢您的任何建议。
基督教
使用关键字“ pipeline”将管道传递给“ command”:
db.command('aggregate', 'mycol', pipeline=my_pipeline, explain=True)
Run Code Online (Sandbox Code Playgroud)
例如:
db.command('aggregate', 'mycol', pipeline=[{'$project': {'name': '$field'}}], explain=True)
Run Code Online (Sandbox Code Playgroud)