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

Ensure that find shell helper supports 'let' variables

    XMLWordPrintable

Details

    • Task
    • Status: Backlog
    • Major - P3
    • Resolution: Unresolved
    • None
    • None
    • Shell

    Description

      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" } 
      )
      

      Attachments

        Issue Links

          Activity

            People

              backlog-query-optimization Backlog - Query Optimization
              jason.price@mongodb.com Jason Price
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: