Skip to content

Conversation

@jsatterfield
Copy link

Enable auto commenting by passing query_trace=True and optionally trace_depth=N (defaults to 3) to mongoengine.connect()
Enable the mongo system profiler by connecting to your local mongo and set db.setProfilingLevel(2) on your database.

$ mongo
MongoDB shell version v3.6.5
connecting to: mongodb://127.0.0.1:27017
> use test
switched to db test
> db.setProfilingLevel(2)
{ "was" : 0, "slowms" : 100, "ok" : 1 }
>

This covers most read ops. Inserts, updates, upserts, findAndModify, etc wont get comments.
Example system.profile doc with comments:

$ mongo
MongoDB shell version v3.6.5
connecting to: mongodb://127.0.0.1:27017
> use test
switched to db test
> db.system.profile.find({"ns": { $ne: "test.system.profile"}}).sort({$natural: -1}).limit(1).pretty()
{
	"op" : "query",
	"ns" : "test.foo",
	"query" : {
		"find" : "foo",
		"filter" : {
			"first_name" : "James"
		},
		"ntoreturn" : -1,
		"comment" : [
			"<ipython-input-4-460f39f6836a>(1)",
			"/Users/jsatterfield/venv/test/lib/python2.7/site-packages/IPython/core/interactiveshell.py(2869)",
			"/Users/jsatterfield/venv/test/lib/python2.7/site-packages/IPython/core/interactiveshell.py(2815)"
		]
	},

dggreenbaum added a commit that referenced this pull request Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants