I'm stuck somewhere about Mongodb aggregate about array modification.
my array looks like this:
[
{
location: {
open: true,
expected: [
"foo",
"bar",
"baz"
]
}
}
]
I wanna find and replace specific value and convert to ObjectId.
I have tried using this pipeline:
[
{
$match: {
"location.expected": {$eq: "foo"}
},
}
{
$set: {
"location.expected": {
$map: {
input: "$location.expected",
as: "loc",
in: {
$replaceAll: {
input: "$$loc",
find: "foo",
replacement: "60783e804136605b0a48bfe8"
}
}
}
}
}
}
]
it work now. but I cannot convert to ObjectId, replaced value.
so, I simple solution about find & replace & convert specific simple array value.
thanks for all.