[SERVER-40530] Comment option in aggregation does not seem to produce effect Created: 08/Apr/19  Updated: 09/Apr/19  Resolved: 09/Apr/19

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 3.6.12
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Dani Assignee: Eric Sedor
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

Mongo 3.6

db.setProfilingLevel(2);db.movies.insert({ "title" : "Jaws", "year" : 1995, "imdb" : "tt0073195" });
db.movies.insert({ "title" : "A Clockwork Orange", "year" : 1971, "imdb" : "tt0066921" });

The aggregation

 

{{db.movies.aggregate( [ { $match:

{ year : 1995 }

} ], { comment : "year_95_query" } );}}

 

 

is shown in system.profile as follows:

{{}}{{{ }}
{{ "op" : "command", }}
{{ "ns" : "movies.movies", }}
{{ "command" : {}}
{{ "aggregate" : "movies", }}
{{ "pipeline" : [ { "$match" :

{ "year" : 1995 }

} ], }}
{{ "cursor" : { }, }}
{{ "$db" : "movies", }}
{{ "$readPreference" : { "mode" : "primaryPreferred" }}}
{{ }, }}
{{ "keysExamined" : 0, }}
{{ "docsExamined" : 2, }}
...

 

 

Where the old $comment in a $match stage

 

{{db.movies.aggregate( [ { $match:

{ year : 1995, $comment : "year_95_query" }

} ] );}}

 

is shown as:

 

{{{ }}
{{ "op" : "command", }}
{{ "ns" : "movies.movies", }}
{{ "command" : {}}
{{ "aggregate" : "movies", }}
{{ "pipeline" : [ { "$match" :

{ "year" : 1995 }

} ], }}
{{ "cursor" : { }, }}
{{ "$db" : "movies", }}
{{ "$readPreference" : { "mode" : "primaryPreferred" }}}
{{ }, }}
{{ "keysExamined" : 0, }}
{{ "docsExamined" : 2, }}
{{ ...}}

Participants:

 Description   

The docs say the comment option's string should appear like this:
{{{
"op" : "command",
"ns" : "movies.movies",
"command" : {
"aggregate" : "movies",
"pipeline" : [
{
"$match" :

{ "year" : 1995 }

}
],
"comment" : "year_95_query",
"cursor" : {}}

 

But the comment string is nowhere to be seen in system.profile



 Comments   
Comment by Eric Sedor [ 09/Apr/19 ]

Understood Dani, and no problem!

Comment by Dani [ 09/Apr/19 ]

Ok, it's MongoDB 3.6.8 but never mind. Tested again from the real mongo shell this time and you're right, it works as expected. I was working from the shell in Studio 3T and it doesn't work from there.

Really weird since it's configured to use the real mongo binary from the brew install directory /usr/local/Cellar/mongodb@3.6/3.6.8_1/bin/mongo but I'll take it up with them.
Apologies for the inconvenience.

Dani

Comment by Eric Sedor [ 09/Apr/19 ]

This documentation shows how to provide comments within the aggregation framework, while this documentation describes how to provide a comment as a command option.

We have not been able to reproduce the omission of either form in a system.profile collection in MongoDB 3.6.12. Can you let us know if this omission is recurring in a specific maintenance release of 3.6.X?

> db.version()
3.6.12
> db.setProfilingLevel(2)
{ "was" : 0, "slowms" : 100, "sampleRate" : 1, "ok" : 1 }
> db.movies.aggregate( [ { $match:  { year : 1995 } } ], { comment : "year_95_query" } )
> db.movies.aggregate( [ { $match:{ year : 1995,$comment : "year_95_query" }} ] )
> db.system.profile.find().pretty()
{
	"op" : "command",
	"ns" : "test.movies",
	"command" : {
		"aggregate" : "movies",
		"pipeline" : [
			{
				"$match" : {
					"year" : 1995
				}
			}
		],
		"comment" : "year_95_query", // ****** Comment as a command option
		...
	},
	...
}
{
	"op" : "command",
	"ns" : "test.movies",
	"command" : {
		"aggregate" : "movies",
		"pipeline" : [
			{
				"$match" : {
					"year" : 1995,
					"$comment" : "year_95_query" // ****** Comment as a query operator
				}
			}
		],
		"cursor" : {
		},
		...
	},
	...
}

Comment by Dani [ 09/Apr/19 ]

I messed up the output of the $comment in

Where the old $comment in a $match stage

Should read like this:

 

{ 
    "op" : "command", 
    "ns" : "movies.movies", 
    "command" : {
      "aggregate" : "movies", 
      "pipeline" : [ { $match" : { "year" : 1995, "$comment" : "year_95_query" } } ], 
      "cursor" : { }, 
      "$db" : "movies", 
      "$readPreference" : { "mode" : "primaryPreferred" }
    }, 
    "keysExamined" : 0, 
    "docsExamined" : 2, 
 ...

 

Generated at Thu Feb 08 04:55:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.