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

$let in the $lookup pipeline only allows variable names with lower cases

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.6.1
    • Component/s: Aggregation Framework
    • Labels:
      None
    • ALL

      In the mongodb document:

       

      https://docs.mongodb.com/master/reference/operator/aggregation/lookup/index.html#lookup-uncorrelated-subuery

       

      The example query:

      db.orders.aggregate([
      {
      $lookup:

      { from: "warehouses", let: \{ order_item: "$item", order_qty: "$ordered" }

      ,
      pipeline: [
      { $match:
      { $expr:

      { $and: [ \{ $eq: [ "$stock_item", "$$order_item" ] }

      ,
      { $gte: [ "$instock", "$$order_qty" ] }
      ]
      }
      }
      },
      { $project:

      { stock_item: 0, _id: 0 }

      }
      ],
      as: "stockdata"
      }
      }
      ])

       

      This runs fine, but if the line:

      let: { order_item: "$item", order_qty: "$ordered" },

      is replaced by:

      let: { ORDER_ITEM: "$item", ORDER_QTY: "$ordered" },

      and replace these variables in the other two lines:

       

      { $eq: [ "$stock_item", "$$ORDER_ITEM" ] }

      ,
      { $gte: [ "$instock", "$$ORDER_QTY" ] }

      The mongo shell returns error:

       

      assert: command failed:

      { "ok" : 0, "errmsg" : "'ORDER_ITEM' starts with an invalid character for a user variable name", "code" : 16867, "codeName" : "Location16867" }

      : aggregate failed

      _getErrorWithCode@src/mongo/shell/utils.js:25:13

      doassert@src/mongo/shell/assert.js:16:14

      assert.commandWorked@src/mongo/shell/assert.js:403:5

      DB.prototype._runAggregate@src/mongo/shell/db.js:260:9

      DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1212:12

      @(shell):1:1

       

      2018-05-07T18:11:21.195-0400 E QUERY    [thread1] Error: command failed:

      { "ok" : 0, "errmsg" : "'ORDER_ITEM' starts with an invalid character for a user variable name", "code" : 16867, "codeName" : "Location16867" }

      : aggregate failed :

      _getErrorWithCode@src/mongo/shell/utils.js:25:13

      doassert@src/mongo/shell/assert.js:16:14

      assert.commandWorked@src/mongo/shell/assert.js:403:5

      DB.prototype._runAggregate@src/mongo/shell/db.js:260:9

      DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1212:12

      @(shell):1:1

       

       

       

            Assignee:
            schwerin@mongodb.com Andy Schwerin
            Reporter:
            jliuecmd@yahoo.com Jun Liu
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: