def __2(db): for user in db.users.find(): user['firstName'], user['lastName'] = user['name'].split() del user['name'] db.users.save(user) __3 = """ db.users.find().forEach(function(u) { u.initials = u.firstName[0] + u.lastName[0]; db.users.save(u); }) """ def __4(db): db.users.update({}, {'$set': {'last_update': datetime.datetime.utcnow()}}) if __name__ == '__main__': change_sets = ( pycall('1', '*****@*****.**', __1, 'It\'s a comment! The change set is executed with a python callback.'), pycall('2', '*****@*****.**', __2), js('3', '*****@*****.**', __3, 'This change set is an inline js which is executed by\ the MongoDB engine.'), pycall('4', '*****@*****.**', __4, always=True), ) run(MongoClient().test, change_sets)
import time from pymongo import MongoClient from pyliquib import pycall, run def __1(db): time.sleep(10) # run the file with few threads if __name__ == '__main__': change_sets = ( pycall('1', '*****@*****.**', __1, 'A sleeper'), ) run(MongoClient().test, change_sets)