I'm having a problem in updating an array in my Records table named projects->url.
Records collection
id: 1
status: "failed"
projects: Array
0: Object
url: www.facebook.com/testing/myprofile/1234
1: Object
url: www.facebook.com/testing/myprofile/12345
2: Object
url: www.facebook.com/testing/myprofile/123456
createdAt: Wed Dec 02 2020 16:17:26 GMT+0800
updatedAt: Wed Dec 02 2020 16:17:26 GMT+0800
id: 2
status: "passed"
projects: Array
0: Object
url: www.facebook.com/testing/myprofile/5
1: Object
url: www.facebook.com/testing/myprofile/6
2: Object
url: www.facebook.com/testing/myprofile/7
createdAt: Wed Dec 02 2020 16:17:26 GMT+0800
updatedAt: Wed Dec 02 2020 16:17:26 GMT+0800
This is my aggregate pipeline using map to update the array of the projects field but it doesn't update the url field.
dbo.collection('records').aggregate(
[{
$project:
{
projects:
{
$map:
{
$replaceOne: { input: "$projects.url", find: "facebook", replacement: "mywebsite"}
}
}
}
}]
)
I want the records projects url to be from facebook.com -> mywebsite.com
Result
Records
id: 1
status: "failed"
projects: Array
0: Object
url: www.mywebsite.com/testing/myprofile/1234
1: Object
url: www.mywebsite.com/testing/myprofile/12345
2: Object
url: www.mywebsite.com/testing/myprofile/123456
createdAt: Wed Dec 02 2020 16:17:26 GMT+0800
updatedAt: Wed Dec 02 2020 16:17:26 GMT+0800
id: 2
status: "passed"
projects: Array
0: Object
url: www.mywebsite.com/testing/myprofile/5
1: Object
url: www.mywebsite.com/testing/myprofile/6
2: Object
url: www.mywebsite.com/testing/myprofile/7
createdAt: Wed Dec 02 2020 16:17:26 GMT+0800
updatedAt: Wed Dec 02 2020 16:17:26 GMT+0800