from pymongo import MongoClient

# 连接到 MongoDB 本地实例
client = MongoClient('mongodb://admin:password@localhost:27017/')

# 连接到数据库
db = client['b017bdb']

# 连接到集合
collection = db['test_collection']

# 插入一条数据
collection.insert_one({"name": "Alice2", "age": 21})

# 查询所有数据
for doc in collection.find():
    print(doc)

# 关闭连接
client.close()