Each version of this package is quite closely tied to individual an pymongo
version (or a small range of versions), as it relies on pymongo
internals.
Supported pymongo
version: 3.7.1
Supported operations:
save
delete_one
delete_many
insert
insert_one
find
find_one
remove
replace_one
update
update_one
Unsupport operations
insert_many
import pymongo
from pymongo_basic_profiler import OpTracker
with OpTracker() as op_tracker:
client = pymongo.MongoClient()
db = client.test_optracker_db
db.people.insert({'name': 'Jane Doe', 'email': '[email protected]'})
db.people.find_one({'email': '[email protected]'})
db.people.find_one({'name': 'Jane Doe'})
assert len(op_tracker.inserts) == 1
assert len(op_tracker.queries) == 2
assert op_tracker.queries[0]['result'] == [
{
'_id': ObjectId('5ba3635b037b306569dce4bf'),
'name': 'Jane Doe',
'email': '[email protected]',
}
]
I have not been able to find a project that does the same. If you find one -- please let me know. There's most likely no reason to maintain two libraries with the same purpose.
The following projects also monkey patch pymongo
in order to track queries: