An error occurred while loading data for this chart

Hi, i was trying to investigate the error on the chart scrapping while try to binning with parameter given from my company on MonogDB Chart, it shows an error while loading which stated conversionFailure attached on the screenshot. The chart was shown when i put a field to series, but when i turned on binning it show the error. Idk but the other chart showing just fine. Any advice regarding this issues?

the value expression on that field (calculated status) =

{
  $cond: {
    if: {$eq: ["$status", "failed to login"]},
    then: {$first: "$lastScraperStatus"},
    else: "$status"
  }
}

while binning consist of several item

is that error show because of the binning which then related from the backend scrapper? or there is something wrong while converting on the data


here is the binning

also here is the error

Hey @Yudha_C.M_Yusuf - sorry to hear you’re having issues.

Looking at your chart definition, I suspect the issue is that the calculated field is returning an object value for at least one document.

We’ll see if we can add some more protection for this case in our string binning logic, but in the meantime you should be able to fix it by wrapping your calculated field in a $convert statement including an onError value.

Let me know if this works!
Tom

Hey Tom, Thanks for your response i really want to try your advice, but how do i put that $convert thing on the chart? is that on the field value that i put in? sorry if it is a dumb question, im kinda new with mongodb and still learning

Hey Tom, thanks for your suggestion the chart works for now.
but it seems some parameter is missing, is it because the convert+onerror value makes the previous error group into one as other values?

image

image

any advice if i want the parameter shown on the chart Tom, should i convert the data object first from the scraper before used it on mongodb chart by make some convert pipeline?

ah and i forgot mention this at the beginning
image
so an [object object] on the chart parameter shows before i use the binning logic, this should be the one who made the “error:13 unsupported conversion from object to string” on the first place

Hi @Yudha_C.M_Yusuf -

Looking at your conversion, I suspect the issue is that the object value is in at last one document for the status field, but your converion is for the lastScraperStatus. Given your data is not showing either of your error messages, I suspect that means there are no values in lastScraperStatus that are failing to convert. Have you tried doing the $convert on the $status value in your else clause?

Tom

Hi @tomhollander
I’ve already tried doing the $convert on the $status value in else clause and it still showing the same error object to string which "FunctionError: (ConversionFailure) Unsupported conversion from object to string in $convert with no onError value"

so i think is it better to use it on the lastscraperstatus isnt it?

I’m not sure what your data looks like, but given Binning is failing because some of your values are objects, I suspect the safest thing to do would be to convert both values to strings with the onError block. So something like this:

	$cond: {
		if: {$eq: ["status", "failed to login"]},
		then: {$convert: {
			input: "$lastScraperStatus",
			to: "string",
			onError: "An error occurred",
			onNull: "Input was null or empty"
			}},
		else: {$convert: {
			input: "$status",
			to: "string",
			onError: "An error occurred",
			onNull: "Input was null or empty"
			}},
	}
}

In your original example you were using $first against lastScraperStatus; you may need to add that back in if it’s important.

LMK if this helps.
Tom

yeah it works thank you @tomhollander !!

im still curious, can you correct me if im worng or give me some explanation:

  • the binning logic is automatically created from the mongodb itself right? so whatever shows when i want to binning some label is a value that mongodb detect from collection?
  • is it possible to aggregate raw data from back-end side (scraper things) to wind or unwind the value? I mean my problem above could be done also by modify the aggregate pipeline (example fom compasss)

for the 2nd question i cant explain it clearly, otherwise the problem is solved, its just my curiousity. Thanks again @tomhollander ! :slight_smile:

Awesome, glad it’s working.

Everything you do in the chart builder, including calculated fields and binning, results in stages being added to an aggregation pipeline. You can view the pipeline from the … button at the top right of the window.

If you want, you can write your own pipeline in the query bar. This will still be combined with the options in the chart builder, but you may find you can do it more efficiently for your scenario.

Tom

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.