You can simply aggregate to find all the matching records with regex "/?=view"
and the loop over to update it one by one as below:
> db.product.find()
{ "_id" : ObjectId("5e0c86a4a2e621133ea3b041"), "url" : "https://stackoverflow.com/questions/ask" }
{ "_id" : ObjectId("5e0c86b1a2e621133ea3b042"), "url" : "https://stackoverflow.com/questions/ask100?=view" }
{ "_id" : ObjectId("5e0c86c1a2e621133ea3b043"), "url" : "https://stackoverflow.com/questions/ask101" }
>
>
> db.product.aggregate( [
{ $match: { url: { $regex: "/?=view" } } },
{ $addFields: { url: { $split: [ "$url", "?" ] } } }
]).forEach(function(matchedDoc) {printjson(matchedDoc);
db.product.updateOne({_id: matchedDoc._id}, {$set: {url: matchedDoc.url[0]} } )}
)
{
"_id" : ObjectId("5e0c86b1a2e621133ea3b042"),
"url" : [
"https://stackoverflow.com/questions/ask100",
"=view"
]
}
> db.product.find()
{ "_id" : ObjectId("5e0c86a4a2e621133ea3b041"), "url" : "https://stackoverflow.com/questions/ask" }
{ "_id" : ObjectId("5e0c86b1a2e621133ea3b042"), "url" : "https://stackoverflow.com/questions/ask100" }
{ "_id" : ObjectId("5e0c86c1a2e621133ea3b043"), "url" : "https://stackoverflow.com/questions/ask101" }
>