I have a set of URLs stored in a MongoDB collection, and you want to replace the base URL of these URLs while preserving the rest of the path and query string. The URLs you want to replace are:
https://url1/uploads/…
https://url2/uploads/…
https://url2/uploads/…
You want these URLs to be converted to:
https://urlForAmazonaws/…
the urlForAmazonaws URL where the images or resources are now hosted.
input: "$image",
as: "item",
in: {
$replaceOne: {
input: "$$item.path",
find: "^https://(url1|url2|url3)/uploads/",
replacement: "https://urlForAmazonaws/"
}
}
I handled the URL replacement like this and expected the final result to be https://urlForAmazonaws/. However, I was surprised that this did not happen. The final result ended up being one of the three original URLs, as nothing changed.