Replacing parts of a string is something we want to do quite often, but unfortunately MongoDB doesn't currently have a simple way to do it. There's a bug that I hope will be accepted and make this post out of date by the time you're reading.

db.coll.update(
  {'entry' : /hate/},
  {$replace : {'entry' : ['hate', 'love']}}
);

This would replace the string hate with love in the value of the field entry, where the string to find could also be a regex.

So, that doesn't work yet. Instead, we can do this.

db.coll.find({'entry' : /hate/}).forEach(function(e) {
    var parts = e.stem.split('hate');
    e.stem = parts.join('love');
    db.coll.save(e);
});

This will find all the entry fields and loop through them. For each field, the value is split on the string hate, and we then join the split parts back together around the replacement string, love.

Not quite as elegant, but it works.