I believe MongoDB's server side functions allow you to create an atomic grouping of operations.. i.e. store a function and call it by db.eval()
See the following:
http://www.mongodb.org/display/DOCS/Server-side+Code+Executi... http://www.mongodb.org/display/DOCS/Server-side+Code+Executi...