Moralis Database is not recognizing interpolated string

Hello, I am running a query to filter for deposits based on a user’s account. However, I am running into an issue where the server will only return results if the account value is a string, but not for an interpolated string. Obviously this is an issue to dynamically return data for different users as they come to the site.

This filter does return correct results:

query.equalTo("user", "0xa638ec13a0905a66b84876a1c89e262a647feb37");

This filter does not return correct results:

query.equalTo("user", `${0xa638ec13a0905a66b84876a1c89e262a647feb37}`);

Any ideas what could be happening here?

Can you try to log that parameter first to see if it has the expected value?

Logs as a string

console.log(typeof `${0xa638ec13a0905a66b84876a1c89e262a647feb37}`);
=> string

And the value is the expected one?

the value I am sending to your server? yup that is the correct account value, as it returns the correct expected values from the DB when I submit it like this:

"0xa638ec13a0905a66b84876a1c89e262a647feb37"

I mean when you use the other option, if you just log it if it works as expected

Ah yes it also returns as a string

console.log(typeof "0xa638ec13a0905a66b84876a1c89e262a647feb37");
=> string

why do you want to pass an interpolated string at it normal state ?
console.log(typeof ${0xa638ec13a0905a66b84876a1c89e262a647feb37}); => string this will return a string because it is a string, but then there is no value in the address, the address is a string ?
have you tried something that store actual values ?

Well I want to to interpolate account from useMoralis, but I figured for the purpose of an example just using a real account would be better. So to your point it’d look like this:

query.equalTo("user", account);

For the purpose of this example I wouldnt need to interpolate account, but if there are other values that would need to be interpolated then it might be an issue - I’m really just asking if this is an known issue, thought it was interesting and wanted to bring up

have you tried printing

console.log(`${0xa638ec13a0905a66b84876a1c89e262a647feb37}`);

it doesnt print the address, it is impossible
------>> 4.892396856465559e+47
you can do this

 query.equalTo("user", `${account}`);

but accounts has to be a string and has the string literals
this should be fyn

var accounts = "0x55b24428b062058A47B9E4F69C9A8803d9bBBB41";
console.log(`${accounts}`);

summary:
This will return a string as the type, but the value will be different

console.log(typeof `${0xa638ec13a0905a66b84876a1c89e262a647feb37}`);
=> string

and if you have console log it, you will know or you can look at the value above
and the DB obviously doesn’t have a value like that

ahh ok ok I see what you mean, the account is being converted to the float, then turned into a string and sent to db, and thus not matching any of the accounts in the db… thanks for clarifying that!

yes, it is been messed up by javascript

1 Like