Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto comment - WIP #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Auto comment - WIP #19

wants to merge 3 commits into from

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.

1 participant