Converting a string type hex number to a decimal?

Is there an aggregation operator that can convert a string type hex to a decimal? We are working with blockchain data and have run into cases like this quite often.

Hi @Kuan_Huang,

Welcome to MongoDB community!

Have you tried to use a $convert or $toDouble operator in a project or addFields stage?


That works. Thank you!

case 2:

Actually there is a problem. It seems to work in below in case 1 but not in case 2:

case 1:

Hi @Kuan_Huang ,

As you can see the projection stage preview results in no value for “b” therefore its null later.

I would use $addFields and have represantation of a binary string via the extended json represtation :


Thank you. I will find sometime to explore it and get back to you.

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