pymongo aggregate don't allow explain option
Asked Answered
P

1

5

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

Ping answered 28/4, 2017 at 9:47 Comment(0)
F
10

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)
Friedrick answered 28/4, 2017 at 15:29 Comment(1)
how to get execution stats? #56253608Longboat

© 2022 - 2024 — McMap. All rights reserved.