MongoDB Chart "Cannot retrieve data"

Just to close off the loop here. As discussed offline, in this particular case, the authenticated embedding uses App Service as authentication provider with the “Fetch data using Atlas App Services” enabled. When rules configured in App Services, it will only support aggregation stages/expressions supported by MongoDB 4.4 for user functions. $dateSubtract is an aggregation expression that has been added with MongoDB 5.0, hence the App Service raised an error which causes the “Cannot retrieve data” error in Charts.

Until the 5.0 aggregation expression is supported, the workaround for this issue is to disable the “Fetch data using Atlas App Services” option from the authentication provider setting.