I have a multiselect and am trying to use the selected values in a MongoDB aggregation with $in
.
The multiselect has three values, "a", "b", and "c".
If I try to use it like this:
"field": {
"$in":{{myMultiSelect.values}}
},
the editor gives an error saying
The value has to be of type 'object | void', you provided 'string'
and shows the preview output as:
"field": {
"$in":a,b,c
},
I have tried changing the template to this:
"field": {
"$in":[{{myMultiSelect.values.map(v => `\"${v}\"`)}}]
},
which produces a correct preview
"field": {
"$in": ["a","b","c"]
},
but then the database receives the value as this:
"field": {
"$in": [ [ "\"a\"", "\"b\"", "\"c\"" ] ]
}
There seems to be some mismatch between the preview and what is actually sent to the database when the query is run, since my first attempt does send the correct format to the database, even though it looks wrong in the preview. When changing the multiselect selection, the query also does not run automatically, which might be caused by the same issue.