访问DataBase
database = client["testdb"]
访问集合
collection = database["testcollection"]
显示的创建一个集合
gold_member_conllection = database.create_collection("gold_member")
插入数据
document = {"name": "ff", "age": 30, "email": "ff11@ctyun.com"}
gold_member_conllection.insert_one(document)
删除数据
result = collection.delete_one({'name': 'ff'})
删除collection
database.drop_collection("test")
读数据
query = {"name": "ff"}
result = collection.find_one(query)
print(result)
运行命令
database.command("collstats","test")
database.command("buildinfo")
计数
count = gold_member_conllection.find().count()
排序
results = gold_member_conllection.find().sort('name',1)
创建索引
result=database[gold_member_conllection].create_index([('name',1)])