pymongo使用方法

鏈接MongoDB
     鏈接MongoDB咱們須要使用PyMongo庫裏面的MongoClient,通常來講傳入MongoDB的IP及端口便可
client  =  pymongo.MongoClient(host = '127.0.0.1' , port = 27017 )
# 指定數據庫
# MongoDB中還分爲一個個數據庫,咱們接下來的一步就是指定要操做哪一個數據庫
db  =  client['tencent']
# 指定集合
# MongoDB的每一個數據庫又包含了許多集合Collection,也就相似與關係型數據庫中的表,
collection  =  db.students
或collection = db['students']
student  =  {
     'id' '20170101' ,
     'name' 'Jordan' ,
     'age' 20 ,
     'gender' 'male'
}
result  =  collection.insert(student)
print (result)
相關文章
相關標籤/搜索