[SERVER-11469] add a user-defined $tag attribute to queries that shows up in db.currentOp().inprog Created: 30/Oct/13  Updated: 10/Dec/14  Resolved: 27/Jun/14

Status: Closed
Project: Core Server
Component/s: Admin, Querying
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: troy molsberry Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

Interactive database applications typically require a "cancel" button for the user to stop a long running operation. Mongodb does not provide this ability, partly due to the closure of https://jira.mongodb.org/browse/SERVER-5605

Ideally, a query could be annotated with a $tag that will show up in db.currentOp().inprog output so that an application can track and potentially killOp() any queries in progress.



 Comments   
Comment by troy molsberry [ 27/Jun/14 ]

if the query exceeds 256 bytes then the comment field in the db.currentOp() output shows "query not recording too large"

Comment by Thomas Rueckstiess [ 27/Jun/14 ]

Hi Troy,

This feature already exists, you can use the $comment operator to annotate queries. This will show up in the profiler and db.currentOp() under the query field.

I've made a quick example to demonstrate.

First I insert a document and then find it again. For the query, I added a $comment with the _addSpecial() method in the shell. (To simulate a long-running query I added a $where clause that executes a sleep in the server-side javascript interpreter. You wouldn't normally need that).

MongoDB shell version: 2.6.1
connecting to: test
> db.foo.insert({a: 1})
WriteResult({ "nInserted" : 1 })
> db.foo.find({a:1, $where: "sleep(1000000)"})._addSpecial("$comment", "this is a comment")

In another mongo shell, we can inspect the db.currentOp()

MongoDB shell version: 2.6.1
connecting to: test
> db.currentOp()
{
	"inprog" : [
		{
			"opid" : 47,
			"active" : true,
			"secs_running" : 6,
			"op" : "query",
			"ns" : "test.foo",
			"query" : {
				"query" : {
					"$where" : "sleep(1000000)",
					"a" : 1
				},
				"$comment" : "this is a comment"
			},
			"client" : "127.0.0.1:51650",
			"desc" : "conn8",
			"threadId" : "0x112418000",
			"connectionId" : 8,
...

As you can see, the $comment made it into the db.currentOp() output and shows up in the query part.

I hope that helps.

Regards, Thomas

Generated at Thu Feb 08 03:25:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.