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

arrayToObject should probably accept missing values

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

      (somewhat related to SERVER-29676 which allowed explicit null for `v` field)

      Currently trying to create dynamic object out of existing values causes an error if a value used is missing:

      //input
      {a:5}
      {a:null}
      {a:missing} 
      // agg stage
      {$set:{d:{$arrayToObject:[ [k:"keyA", v:"$a"] ]}}} 
      // expected output:
      {a:5, d:{keyA:5}}
      {a:null, d:{keyA:null}}
      {d:{}}
      // but instead we get this:
      "errmsg" : "PlanExecutor error during aggregation :: caused by :: $arrayToObject requires an object keys of 'k' and 'v'. Found incorrect number of keys:1"
      

      Note that this is much unfriendlier than old error which used to provide additional information (Missing either or both keys from: {k: \"comment\", v: null}"

      However, is there a valid reason to reject missing `v`? It's an expression which resolves to bson value `missing` - it's not actually missing from the expression.

      As it is now, user will have to always remember to write

      v:{$ifNull:["$a",null]}
      

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            asya.kamsky@mongodb.com Asya Kamsky
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: