How to update subset of a string in MongoDB?
问题 I want to update the following subset of a string in monogdb Collection: Paper Field: URL Document Current: Name : House URL : www.home.com/300x300 Document Updated Name : House URL : www.home.com/600x600 I have already tried this but it doesn't seem to be working: db.Paper.find({Name:"House"}).forEach(function(e,i) { e.URL=e.URL.replace("300","600"); db.Paper.save(e); }); Any ideas? 回答1: You can use one of the following aggregations to query and update: db.test.aggregate( [ { $match: { url: