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

Allow individual updates to accept parameters for non-pipeline updates

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

      Currently in the update command, if you specify 'c' in the individual element of the 'updates' array, and the update description 'u' is not a pipeline-update, you'll get an error "code: 51198, errmsg: 'Constant values may only be specified for pipeline updates'".

      db.people.insertOne({name: "Andy"})
      db.runCommand(
         {
           update: "people",
           updates: [
             { 
              q: { $expr: { $eq: [ "$name", "$$nameVar" ] } }, 
              u: {  $inc: { score: 1 } }, 
              multi: true,
              c: {nameVar: "Andy"}
              }
           ]
         }
      )
      

      This prevents using parameters defined in 'c' in the 'q' filter part of the update.
      Also, it is not consistent with 'let' where you can set parameters on the command level, and it will not produce an error for the non-pipeline updates.

      db.runCommand(
         {
           update: "people",
           updates: [
             { 
              q: { $expr: { $eq: [ "$name", "$$nameVar" ] } }, 
              u: {  $inc: { score: 1 } }, 
              multi: true
              }
           ],
           let: {nameVar: "Andy"}
         }
      )
      

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            kateryna.kamenieva@mongodb.com Katya Kamenieva
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: