Generalnie nie jest to poprawne:jeśli masz ciąg https://aaa/xxx/aaa (yyy równa się aaa ) otrzymasz https://bbb/xxx/bbb .Ale jeśli się z tym zgadzasz, kod zadziała.
Aby dodać informacje debugowania, użyj print funkcja:
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);
}
(A tak przy okazji, jeśli chcesz drukować obiekty, jest też printjson funkcja)