def get_student(self): ''' get all student from db :return: list of student ''' students=student_manager.student_collection("college","localhost") res =students.get_students() return res
def get_student_from_replicaset(self,port): ''' get student data from specific server in the replica set :param port:server port :return: list of student ''' students=student_manager.student_collection("college","localhost",port) res =students.get_students() return res
def add_student(self,doc): ''' add one document to student collection :param doc: -json object to insert to student collection ''' for retry in range (4): try: students=student_manager.student_collection("college","localhost") students.insert_students(doc) db_log.debug( "Inserted Document: ") time.sleep(.1) break except pymongo.errors.AutoReconnect as e: db_log.error("Exception ",type(e), e) db_log.debug( "Retrying..") time.sleep(5) except pymongo.errors.DuplicateKeyError as e: db_log.debug( "duplicate..but it worked") break
def delete_student_collection(self): ''' delete all students from students collection ''' students=student_manager.student_collection("college","localhost") students.delete_students({})