I have been working with MongoDB (and Metabase). Metabase way of searching is based on Mongo aggregation pipelines.
For people that don't know, Metabase allows us to create charts, and you can define filters for those charts, and use those filters on your Mongo query.
Anyway, the only filter types I can have are: String, Number and Date.
But, I have a query, that I need to check if a field value is $in some array.
So, I am not able to send an array as a filter. Single number wouldn't work.
My idea was to pass a String (format: "1,3,5,20"), then transform this string in an array of numbers.
Is there a simple way to do this in a single "shot" on Mongo Aggregation? I am trying to not rely on multiple pipeline stages
I know I can use split to generate my array, but from there, I would need to transform all values on my new array of string in integer values.
Any idea?
You should be able to use $map, perhaps:
{$project:{
arrayField: {$map: {
input: {$split: ["$stringField",","]},
as: "elem",
in: {$toInt: "$$elem"}
}}
}}