pymongo聚合体不允许解释选项

时间:2017-04-28 09:47:42

标签: mongodb aggregation-framework pymongo explain

我成功地跑了:

for(i = 0; i < 1; i++)
{
    .
    .
    .

    Wagered[i].Gross_Wage = Wagered[i].Wage * Wagered[i].Days_Worked;
    Wagered[i].Wage_Booking = Wagered[i].Gross_Wage * 0.2;
    Wagered[i].Tax = (Wagered[i].Gross_Wage - Wagered[i].Wage_Booking) * 0.05;
    Wagered[i].Net_Wage = Wagered[i].Gross_Wage - Wagered[i].Wage_Booking - Wagered[i].Tax;
    Wage_Summary += Wagered[i].Net_Wage;

    printf("The Summary of the Gross Wages is: %d\n", Wagered[i].Gross_Wage);
}

现在我尝试:

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})

有什么问题?

感谢您的任何建议。

基督教

1 个答案:

答案 0 :(得分:5)

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

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

例如:

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