Obecně to není správné:pokud máte řetězec https://aaa/xxx/aaa (yyy rovná se aaa ) skončíte s https://bbb/xxx/bbb .Ale pokud s tím souhlasíte, kód bude fungovat.
Chcete-li přidat informace o ladění, použijte print funkce:
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);
}
(Mimochodem, pokud chcete vytisknout objekty, existuje také printjson funkce)