def save(self): ''' Save the list of object in bulk ''' if len(self) > 0: cls = self.__getitem__(0).__class__ if not hasattr(cls, 'getClassName'): raise Exception("Objects must extend BaseObject") col = Database._get_collection(cls.getClassName()) objs = list() for o in self: doc = o.toDict() doc['_id'] = o.getId() del doc['id'] objs.append(doc) col.insert(objs)