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

Ensure that find shell helper supports 'let' variables

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Shell
    • Query Optimization

      The find command supports let parameters, but the db.collection.find() shell helper does not.

      Also, see this JIRA:
      https://jira.mongodb.org/browse/SERVER-51362

      The following test works:

      db.cakeFlavors.drop()
      
      db.cakeFlavors.insert( [
            { _id: 1, flavor: "chocolate" },
            { _id: 2, flavor: "strawberry" },
            { _id: 3, flavor: "cherry" }
       ]  )
      
      db.cakeFlavors.runCommand( {
         find: db.cakeFlavors.getName(),
         let : { targetFlavor: "chocolate" },
         filter: { $expr: { $eq: [ "$flavor", "$$targetFlavor" ] } },
      } )
      

      But the corresponding command using the shell helper fails. I'm not 100% sure I'm executing it properly, as there is no test case for it.

      db.cakeFlavors.find(
        { "$flavor": { "$$targetFlavor" } },
        { let: { targetFlavor: "chocolate" } }
      )
      

      I also tried this, which also generated an error:

      db.cakeFlavors.find(
        { "$flavor": { "$$targetFlavor" } },
        let: { targetFlavor: "chocolate" } 
      )
      

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            jason.price@mongodb.com Jason Price
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: