Python数据存入MongoDB

注意
存入MongoDB数据库中的数据类型必须是{key: value}型的。

import pymongo

# 配置数据库信息
MONGO_URl = 'localhost'
MONGO_DB = 'taobao' # 数据库名
MONGO_TABLE = 'iphonex_url' # 表名

# 连接数据库
client = pymongo.MongoClient(MONGO_URl)
db = client[MONGO_DB]

# 存入数据库
def save_url_to_Mongo(result):
    try:
        if db[MONGO_TABLE].insert(result):
            print('存储到MongoDB成功', result)
    except Exception:
        print('存储到MongoDb失败', result)

猜你喜欢

转载自blog.csdn.net/qq_17249717/article/details/81697894
今日推荐