1import pymongo
2conn = pymongo.MongoClient('myserver', 8839)
3db = conn['mydbname']
4coll = db.myCollection
5bulkop = coll.initialize_ordered_bulk_op()
6retval = bulkop.find({'field1':1}).upsert().update({'$push':{'vals':1}})
7retval = bulkop.find({'field1':1}).upsert().update({'$push':{'vals':2}})
8retval = bulkop.find({'field1':1}).upsert().update({'$push':{'vals':3}})
9retval = bulkop.execute()
10