当前位置: 首页 > 工具软件 > PyMongo > 使用案例 >

pymongo

宗政功
2023-12-01

安装

$ python3 -m pip3 install pymongo

创建数据库、集合、字典记录

if __name__ == "__main__":
    mongo_str = "mongodb://localhost:27017/"
    client = pymongo.MongoClient(mongo_str)
    db = client["db_1"]
    col_1 = db["col_1"]
    dict_1 = {"name": "zhangsan", "age": 18}
    x = col_1.insert_one(dict_1)
    print(x)
    print(x.inserted_id)
 类似资料: