[SERVER-68108] $densify with dynamic bounds array causes "A bounding array must contain either both dates or both numeric types" error Created: 18/Jul/22  Updated: 27/Oct/23  Resolved: 05/Aug/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 6.0.0-rc13
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Daniel Cooke Assignee: Sam Mercier
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-68107 $densify with dynamic bounds array ca... Closed
Related
is related to SERVER-66536 Support expressions in $densify range... Closed
Operating System: ALL
Sprint: QO 2022-08-08
Participants:

 Description   

 

I am trying to add missing data to my time series with the `$densify` operator. 

But it does not seem to work when I specify any dynamic values in the bounds array.

*Example*
With a simple data set:
```js
[
   { week: 1, value: 20 },
   { week: 2, value: 30 },
]
```
I want to fill in all weeks *up until todays date

So with the following `$densify` operator I would expect it to work properly:
```js
{
  field: "week",
  range:

{     step: 1,     bounds: [       0,       \{ $week: "$$CLUSTER_TIME" }

    ]
  }
}
```

But I get the following error:

`A bounding array must contain either both dates or both numeric types`

Which does not make sense, because `{ $week: "$$CLUSTER_TIME" }` evalutes to a number, and 0 is definetly a number last I checked.

Sounds like a bug with mongo to me, anyone know?



 Comments   
Comment by Chris Kelly [ 05/Aug/22 ]

Hi Daniel,

Use of expressions in $densify is not currently supported by design. I'll suggest a note to be added to the docs to reflect this since it's came up a few times recently. However, it may be worth posting this to feedback.mongodb.com if you are interested in this feature.

Thanks for your report!
Christopher

 

Comment by Daniel Cooke [ 21/Jul/22 ]

I saw another issue relating to the inability to use expressions in the densify bounds, could this be the real issue ?

Comment by Chris Kelly [ 20/Jul/22 ]

Hi Daniel,

Thanks for your report. I can see how you'd expect this to work. My original hypothesis was that $$CLUSTER_TIME is stored differently internally as BSONType::bsonTimestamp, which is somehow being interpreted differently than numeric value 0. I noticed your reported behavior with $$NOW as well, which I believe is BSONType::Date. However, doing a $toInt or $toDate on any values in $densify will also produce this error, including:

{
  field: "week",
  range: {
    step: 1,
    bounds: [0, {$toInt: 10}]
  }
}

Which also reports "A bounding array must contain either both dates or both numeric types"
As well as trying to cast $toDate in any way.
 
I'll pass this along for more investigation, as I don't immediately see any mention of not being able to use dynamic bounds in the docs. Thanks for your report!

Regards,
Christopher
 
 

Comment by Daniel Cooke [ 18/Jul/22 ]

I copied this issue from my StackOverflow textbox, so the formatting is all off - apologies

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