from pymongo import MongoClient
无密码连接
connection = MongoClient()
有密码连接
conn = MongoClient("10.10.1.114:10321", username="xx", password="xx", authSource="admin")
db = connection.mydb #连接mydb数据库,没有则自动创建
test = db.test ## 使用test集合,没有则自动创建
# 插入单条, 返回x.inserted_id
x = test.insert_one({"name":"zy", "age":25})
# 插入多条
documen=[{"name":"zy", "age":25}, {"name":zs, "age":18}]
x = test.insert_many(document)
for i in test.find({}, {"_id":0}):
print(i)
for i in test.find({"name":"zy"}):
print(i)
test.update_one({"name":"zy"}, {"$set":{"age":26}})
test.remove()