[SERVER-71724] arrayToObject should probably accept missing values Created: 30/Nov/22  Updated: 08/Dec/22

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Asya Kamsky Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Participants:

 Description   

(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]}


Generated at Thu Feb 08 06:19:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.