Establish a connection to MongoDB: official documentation
#coding: Utf-8import pymongoclient = Pymongo. Mongoclient (' 127.0.0.1 ', 27017) # establishes a connection with MongoDB # when there is a user name and password: Pymongo. Mongoclient (' mongodb://username: password @localhost:27017/based on which database is validated ') db = client.xingedb # switch the database used # # # Db.t1.insert_one ({' name ': ' abc ', ' Age ':] # insert_more# # db.t1.update_one ({' name ': ' abc '},{' $set ': {' name ': ' 123 '}}) # update_more# Delete # db.t1.delete_one ({' name ': ' 123 '}) # delete_more# search # cursor = Db.t1.find ({' age ': {' $gt ': +}}) # Returns a Cursor object # find_one## Display method 1:# for I in cursor:# print (i) # # method 2:# Cursor.next () # Cursor.next () # Cursor.next () # Sort,skip,limit Method # # cursor = d B.t1.find ({' age ': {' $gt ': +}}). Sort (' _id ', -1). Limit (1). Skip (1) # # for I in cursor:# print (i) # Count method # Print ( Db.t1.count ())
python--Connecting MongoDB