Info
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?
Top User Comments
JIRAUSER1265262 commented on Fri, 5 Aug 2022 15:00:01 +0000:
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
JIRAUSER1270254 commented on Thu, 21 Jul 2022 18:49:46 +0000:
I saw another issue relating to the inability to use expressions in the densify bounds, could this be the real issue ?
JIRAUSER1265262 commented on Wed, 20 Jul 2022 08:14:36 +0000:
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
JIRAUSER1270254 commented on Mon, 18 Jul 2022 11:55:28 +0000:
I copied this issue from my StackOverflow textbox, so the formatting is all off - apologies