import pymongo
#获取链接mongo对象
client=pymongo.MongoClient("127.0.0.1",port=27017)
#获取数据库
db=client.book
#获取数据集合
collection=db.text
#插入
# collection.insert({"bookname":"莽荒纪"})
#查找全部,这个是一个游标,要遍历才能打印
'''
cursor=collection.find()
for x in collection:
    print(x)
'''
#查找一行
'''
result=collection.find_one({"bookname":"一念永恒"})
print(result)
'''
#更新一条数据
# collection.update_one({"bookname":"莽荒纪"},{"$set":{"bookname":"诡异之主"}})
#更新全部符合的记录
# collection.update_many({"bookname":"诡异之主"},{"$set":{"bookname":"完美世界"}})
#删除一条数据
#collection.delete_one({"bookname":"完美世界"})
#删除全部符合的数据
# collection.delete_many({"bookname":"一念永恒"})
#关闭连接
client.close()