-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Optimization
-
None
-
None
-
None
-
None
-
None
-
None
-
None
(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]}