Het corrigeert over het algemeen niet:als je string https://aaa/xxx/aaa . hebt (yyy is gelijk aan aaa ) krijg je https://bbb/xxx/bbb .Maar als je hiermee akkoord gaat, zal de code werken.
Gebruik print om foutopsporingsinformatie toe te voegen functie:
var cursor = db.test.find();
while (cursor.hasNext()) {
var x = cursor.next();
print("Before: "+x['source']['url']);
x['source']['url'] = x['source']['url'].replace('aaa', 'bbb');
print("After: "+x['source']['url']);
db.test.update({_id : x._id}, x);
}
(En trouwens, als je objecten wilt uitprinten, is er ook printjson functie)