Issue
- I tried to update docs matches query using Mongodb compass
- Even with
$set
(And UI showing updated docs…), Mongodb compass’s aggregation tab is not updating actual documents in collection (ref)
db.collection.aggregate(
[
{
$match: {
URL: { $regex: 'http.*instagram.com/*' }
}
},
{
$set: {
StatusCode: 200
}
}
],
{ maxTimeMS: 60000, allowDiskUse: true }
);
- This aggregation does not affect actual docs even though UI shows you updated fields
Solution
- Installed mongosh and copied rpm file to production server using scp, and then install using command
rpm -i {filename}.rpm
- run
db.collection.updateMany({query}, {$set operation})
inside mongosh
mongosh "mongodb+srv://username:password@mongo-address.com/db"
db.site.updateMany(
{ URL: { $regex: "https://raeperd.github.io/*" } },
{ $set: { StatusCode: 200} }
)
Referenced