# Importing MONGDB module import Pymongo fromPymongo import mongoclient# connect to local server conn= Mongoclient ("localhost",27017) # Connect database db=conn.zhang# Gets the collection student table name collection=db.student"""# Statistics data number res=Collection.find (). Count () # Query all data res=Collection.find () # Ascending res= Collection.find (). Sort (' Age') # Descending res= Collection.find (). Sort (' Age', Pymongo. Descending) # Update data collection.updateone ({'name':'Yuyue'},{'$set':{' Age':3333}}) # Delete condition data collection.remove ({'name':'Yuyue'}) # Delete all data collection.remove () # Insert Data Collection.insert ({'name':'Zhangguanghe',' Age': A,'Addr':'Lishui Jinyang','Phone':18698828830}) # Conditional query Res= Collection.find ({' Age':{'$ne': A}})"""# Disconnect Conn.close ()
Python operation MongoDB Non-relational database