Debugging¶
Understanding the actual MongoDB query¶
Sometimes it is useful to know the actual MongoDB query that is executed,
e.g. for debugging or performance tuning purpose. .inspect()
returns
the actual query that will be executed on accessing the .value
:
property.
om.datasets.get('dfx', lazy=True).query(x__gt=2, x__lt=5).inspect()
=>
{'explain': 'specify explain=True',
'projection': ['x', 'y'],
'query': {'$and': [{'x': {'$lt': 5}}, {'x': {'$gt': 2}}]}}
Explaining the access path¶
To understand the full access path and indicies used by MongoDB, use the
explain=True
keyword.
om.datasets.get('dfx', lazy=True).query(x__gt=2, x__lt=5).inspect(explain=True)
=>
{'explain': {'executionStats': {'allPlansExecution': [],
'executionStages': {'advanced': 4,
'executionTimeMillisEstimate': 0,
'inputStage': {'advanced': 4,
'direction': 'forward',
'docsExamined': 1100,
'executionTimeMillisEstimate': 0,
'filter': {'$and': [{'x': {'$lt': 5}}, {'x': {'$gt': 2}}]},
'invalidates': 0,
'isEOF': 1,
'nReturned': 4,
'needTime': 1097,
'needYield': 0,
'restoreState': 8,
'saveState': 8,
'stage': 'COLLSCAN',
'works': 1102},
'invalidates': 0,
'isEOF': 1,
'nReturned': 4,
'needTime': 1097,
'needYield': 0,
'restoreState': 8,
'saveState': 8,
'stage': 'PROJECTION',
'transformBy': {'_idx#0_0': 1, 'x': 1, 'y': 1},
'works': 1102},
'executionSuccess': True,
'executionTimeMillis': 1,
'nReturned': 4,
'totalDocsExamined': 1100,
'totalKeysExamined': 0},
'ok': 1.0,
'queryPlanner': {'indexFilterSet': False,
'namespace': 'testing3.omegaml.data_.dfx.datastore',
'parsedQuery': {'$and': [{'x': {'$lt': 5}}, {'x': {'$gt': 2}}]},
'plannerVersion': 1,
'rejectedPlans': [],
'winningPlan': {'inputStage': {'direction': 'forward',
'filter': {'$and': [{'x': {'$lt': 5}}, {'x': {'$gt': 2}}]},
'stage': 'COLLSCAN'},
'stage': 'PROJECTION',
'transformBy': {'_idx#0_0': 1, 'x': 1, 'y': 1}}},
'serverInfo': {'gitVersion': '22ec9e93b40c85fc7cae7d56e7d6a02fd811088c',
'host': 'c24ade3fa980',
'port': 27017,
'version': '3.2.9'}},
'projection': ['x', 'y'],
'query': {'$and': [{'x': {'$lt': 5}}, {'x': {'$gt': 2}}]}}