I believe you have 2 options:
1) use pymongo.monitoring
, this link from MongoEngine's doc shows how to configure it.
2) Turn on Profiling with db.setProfilingLevel(2)
, all queries will then be added to the db.system.profile collection
.
E.g: executing this db.users.findOne({'name': 'abc'})
, will add the following to the db.system.profile
collection:
{
"op" : "query",
"ns" : "myDb.users",
"command" : {
"find" : "users",
"filter" : {
"name" : "abc"
},
"limit" : 1,
....
"$db" : "myDb"
},
"keysExamined" : 0,
"docsExamined" : 0,
"cursorExhausted" : true,
"numYield" : 0,
"locks" : {...},
"nreturned" : 0,
"responseLength" : 83,
"protocol" : "op_msg",
"millis" : 0,
"planSummary" : "EOF",
...
"ts" : ISODate("2019-11-20T19:27:13.297Z"),
"appName" : "MongoDB Shell",
"allUsers" : [ ],
"user" : ""
}
As you can see and unfortunately, its not as practical as a SQL query but the information is there