Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-31406

Running aggregate cmd with explain:false is the same as cursor:{}

    XMLWordPrintable

    Details

    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      In the MongoDB shell:

      test> db.version()
      3.5.12-380-g168f195001
      test> db.test.insert([{x:1},{x:2},{x:3}]);
      

      Try aggregating without the cursor document:

      test> db.runCommand({aggregate: "test", pipeline: []})
      {
      	"operationTime" : Timestamp(1507216222, 1),
      	"ok" : 0,
      	"errmsg" : "The 'cursor' option is required, except for aggregate with the explain argument",
      	"code" : 9,
      	"codeName" : "FailedToParse"
      }
      

      Now with the cursor document:

      test> db.runCommand({aggregate: "test", pipeline: [], cursor:{}})
      {
      	"cursor" : {
      		"firstBatch" : [
      			{
      				"_id" : ObjectId("59d64b3c374bbed61ea8ba4a"),
      				"x" : 1
      			},
      			{
      				"_id" : ObjectId("59d64b3c374bbed61ea8ba4b"),
      				"x" : 2
      			},
      			{
      				"_id" : ObjectId("59d64b3c374bbed61ea8ba4c"),
      				"x" : 3
      			}
      		],
      		"id" : NumberLong(0),
      		"ns" : "test.test"
      	},
      	"ok" : 1,
      	"operationTime" : Timestamp(1507216252, 1)
      }
      

      But it behaves the same as passing explain:false

      test> db.runCommand({aggregate: "test", pipeline: [], explain:false})
      {
      	"cursor" : {
      		"firstBatch" : [
      			{
      				"_id" : ObjectId("59d64b3c374bbed61ea8ba4a"),
      				"x" : 1
      			},
      			{
      				"_id" : ObjectId("59d64b3c374bbed61ea8ba4b"),
      				"x" : 2
      			},
      			{
      				"_id" : ObjectId("59d64b3c374bbed61ea8ba4c"),
      				"x" : 3
      			}
      		],
      		"id" : NumberLong(0),
      		"ns" : "test.test"
      	},
      	"ok" : 1,
      	"operationTime" : Timestamp(1507216292, 1)
      }
      

      Show
      In the MongoDB shell: test> db.version() 3.5.12-380-g168f195001 test> db.test.insert([{x:1},{x:2},{x:3}]); Try aggregating without the cursor document: test> db.runCommand({aggregate: "test", pipeline: []}) { "operationTime" : Timestamp(1507216222, 1), "ok" : 0, "errmsg" : "The 'cursor' option is required, except for aggregate with the explain argument", "code" : 9, "codeName" : "FailedToParse" } Now with the cursor document: test> db.runCommand({aggregate: "test", pipeline: [], cursor:{}}) { "cursor" : { "firstBatch" : [ { "_id" : ObjectId("59d64b3c374bbed61ea8ba4a"), "x" : 1 }, { "_id" : ObjectId("59d64b3c374bbed61ea8ba4b"), "x" : 2 }, { "_id" : ObjectId("59d64b3c374bbed61ea8ba4c"), "x" : 3 } ], "id" : NumberLong(0), "ns" : "test.test" }, "ok" : 1, "operationTime" : Timestamp(1507216252, 1) } But it behaves the same as passing explain:false test> db.runCommand({aggregate: "test", pipeline: [], explain:false}) { "cursor" : { "firstBatch" : [ { "_id" : ObjectId("59d64b3c374bbed61ea8ba4a"), "x" : 1 }, { "_id" : ObjectId("59d64b3c374bbed61ea8ba4b"), "x" : 2 }, { "_id" : ObjectId("59d64b3c374bbed61ea8ba4c"), "x" : 3 } ], "id" : NumberLong(0), "ns" : "test.test" }, "ok" : 1, "operationTime" : Timestamp(1507216292, 1) }

      Description

      When running aggregate on MongoDB 3.5.12, it seems like the option explain:false has the same effect as passing an empty cursor document. Per SERVER-24623 the command should be required to pass explain:true or an empty cursor document.

        Attachments

          Activity

            People

            Assignee:
            backlog-query-optimization Backlog - Query Optimization
            Reporter:
            kevin.albertson Kevin Albertson
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Dates

              Created:
              Updated: