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

Serialization error in let variables in a sharded cluster

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 5.0.0-rc2, 5.1.0-rc0
    • None
    • None
    • Fully Compatible
    • ALL
    • v5.0
    • Query Optimization 2021-06-28

    Description

      The following command should work, but doesn't on a mongos:

      {
        aggregate: 'coll0',
        pipeline: [
          {
            '$match': { '$expr': { '$eq': [ '$_id', 2] } }
          },
          { '$project': { _id: 0, y: '$$y'} }
        ],
        let: { y: { '$literal': '$bar' } },
        cursor: {}
      }
      

      If you look at the profiler in the shards, it looks like we just need to preserve a $const or $literal in the serialization. That is dropped and we just end up with y: "$bar":

      {
      	"op" : "command",
      	"ns" : "test.coll0",
      	"command" : {
      		"aggregate" : "coll0",
      		"pipeline" : [
      			{
      				"$match" : {
      					"$expr" : {
      						"$eq" : [
      							"$_id",
      							2
      						]
      					}
      				}
      			},
      			{
      				"$project" : {
      					"_id" : 0,
      					"y" : "$$y"
      				}
      			}
      		],
      		"cursor" : {
      			"batchSize" : NumberLong(101)
      		},
      		"let" : {
      			"y" : "$bar"
      		},
      		"fromMongos" : false,
      		"readConcern" : {
      			"level" : "local",
      			"provenance" : "implicitDefault"
      		},
      		"writeConcern" : {
      			"w" : "majority",
      			"wtimeout" : 0,
      			"provenance" : "customDefault"
      		},
      		"shardVersion" : [
      			Timestamp(0, 0),
      			ObjectId("000000000000000000000000")
      		],
      		"databaseVersion" : {
      			"uuid" : UUID("d40d3f32-02c0-42aa-939d-2d5f640d43b6"),
      			"timestamp" : Timestamp(1622740896, 32),
      			"lastMod" : 1
      		},
      		"lsid" : {
      			"id" : UUID("bd190341-9e6d-4458-b8df-35a7dd5a5072"),
      			"uid" : BinData(0,"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=")
      		},
      		"$clusterTime" : {
      			"clusterTime" : Timestamp(1622741302, 25),
      			"signature" : {
      				"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
      				"keyId" : NumberLong(0)
      			}
      		},
      		"$configTime" : Timestamp(1622741302, 25),
      		"$topologyTime" : Timestamp(1622740776, 3),
      		"$client" : {
      			"application" : {
      				"name" : "MongoDB Shell"
      			},
      			"driver" : {
      				"name" : "MongoDB Internal Client",
      				"version" : "5.0.0-rc0"
      			},
      			"os" : {
      				"type" : "Darwin",
      				"name" : "Mac OS X",
      				"architecture" : "x86_64",
      				"version" : "19.4.0"
      			},
      			"mongos" : {
      				"host" : "charlie-macbook-pro:20003",
      				"client" : "127.0.0.1:54610",
      				"version" : "5.0.0-rc0"
      			}
      		},
      		"$configServerState" : {
      			"opTime" : {
      				"ts" : Timestamp(1622741302, 25),
      				"t" : NumberLong(-1)
      			}
      		},
      		"$db" : "test"
      	},
      	"numYield" : 0,
      	"locks" : {
      		"Global" : {
      			"acquireCount" : {
      				"r" : NumberLong(1)
      			}
      		},
      		"Mutex" : {
      			"acquireCount" : {
      				"r" : NumberLong(2)
      			}
      		}
      	},
      	"flowControl" : {
       
      	},
      	"readConcern" : {
      		"level" : "local",
      		"provenance" : "implicitDefault"
      	},
      	"writeConcern" : {
      		"w" : "majority",
      		"wtimeout" : 0,
      		"provenance" : "customDefault"
      	},
      	"ok" : 0,
      	"errMsg" : "Command let Expression tried to access a field, but this is not allowed because Command let Expressions run before the query examines any documents.",
      	"errName" : "Location4890500",
      	"errCode" : 4890500,
      	"responseLength" : 578,
      	"protocol" : "op_msg",
      	"millis" : 0,
      	"ts" : ISODate("2021-06-03T17:28:30.794Z"),
      	"client" : "127.0.0.1",
      	"appName" : "MongoDB Shell",
      	"allUsers" : [ ],
      	"user" : ""
      }
      

      Attachments

        Issue Links

          Activity

            People

              katherine.wu@mongodb.com Katherine Wu (Inactive)
              charlie.swanson@mongodb.com Charlie Swanson
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: