Hey team,
Here's what I did and the problem I'm facing.
I have a multi-select drop-down named userSelector which is based on a SQL query. The display is the name while the value is ID.
Then I'm passing this in a mongo query as:
{
"$match":{
"userId":{"$in":[{{userSelector.value}}]}
}
}
I have to pass the values inside the [] because otherwise, the mongo query is invalid as $in needs an array input.
When I do this the mongo query built in run time has the value:
{"$in":[["00bff823-7500-4366-8b8c-c8e6ec025d54","01984813-5ad3-451a-b765-db60312b55b8","01d8823e-1400-4bcb-a6a7-b652c1536b4f"]]}
This won't work as it's an array in an array.
If I change it to
{
"$match":{
"userId":{"$in":[{{userSelector.value**.join()**}}]}
}
}
the result is
{"$in":["0172b29e-7a0a-497f-8b22-c582094fb657,01984813-5ad3-451a-b765-db60312b55b8"]}
This won't work as the inner values are not springs themselves but one long string.
If I change it to
{"$in":[{{userSelector.value**.join("\",\"")**}}]}
I get
{"$in":["0172b29e-7a0a-497f-8b22-c582094fb657\",\"01984813-5ad3-451a-b765-db60312b55b8"]}
which is also wrong because the escape characters are not treated correctly.
If I join and split, then again the result is an array in an array. And if I map values to be part of string, I end up with untreated escape chars.
I tried editing the source dropdown's ID value itself to be wrapped in quotes but that too didnt work.
What do I do?