Converting array of numbers into array of strings - problems

Hi Guys,

Loving the tool here more and more :slight_smile: But I am facing an issue and not sure what I can do to resolve it.

I have an array of IP addresses (produced by the “Item List” node, see the image below), in the array, they all appear to have type “string”.

I need to use these IP addresses in the MongoDB query ($in loop). However, when I am editing the expression to create a proper MongoDB query, somehow the strings turn to numbers. And because this is an IP address with dots in it, I am getting a parsing error (ERROR: Unexpected token . in JSON at position 23).

My expression is

{ "ip": {"$in": [{{$json["ip"]}}]}}

And the result window shows correct values (see below):

However, as I close this window and check the query results, the IP addresses are parsed as numbers.
image

Am I doing something wrong? Thanks in advance for your help!

Hi @vnmdr-ap, I think this comment and the discussion around it might answer your question on using an array in your expression.

tl;dr try { "ip": {"$in": {{JSON.stringify($json["ip"])}} }} as your expression which should generate the string you have in mind (this is the JavaScript magic behind it) :wink:

Let me know if you have any questions on this!

Hi @MutedJam , thanks for your help, it worked perfectly! A separate thanks for the tl;dr - learned now how to use expressions better. That opens up a few other opportunities for me (not a fan/don’t really know how to write Function node code :slight_smile: )

It bugged me a lot, why the result when editing the expression window was correct, but as soon as I closed it, it was showing numbers for some reason.

1 Like

Glad to hear this is working for you and thanks so much for confirming :smiley: