123 / n_mongo.py
sin30's picture
Upload n_mongo.py
6275b67 verified
raw
history blame
5.11 kB
import pymongo
def get_mongo_col(col="config_beta"):
"""
获取操作mongo集合
"""
mongo_3012 = "mongodb://dashboard:9qRV71M%25Trx1CI@m3012.hw.mongos.m.com:3012/dashboard?authSource=dashboard"
client = pymongo.MongoClient(mongo_3012, maxPoolSize=500)
db = client["dashboard"]
col = db[col] # data_package(7234543961263854561) goods_feature("7234800834201014260")
return col
# 拿到 collection 对象
collection = get_mongo_col() # 默认 col="config_beta"
doc = collection.find_one(
{"name": "txt2txt_config"},
{"_id": 0, "data": 1}
)
if not doc:
raise RuntimeError("找不到配置 document")
data = doc["data"]
data.append({
'stream_selected': 0,
'label': 'gpt-5',
'value': 'gpt-5',
'wechat_selected': 0,
'wechat_label': 0,
'selected': 0,
'max_tokens': 4000,
'is_think': 1,
'web_label': 0,
'stream_label': 0
})
data.append({
'stream_selected': 0,
'label': 'gpt-5-chat',
'value': 'gpt-5-chat',
'wechat_selected': 0,
'wechat_label': 0,
'selected': 0,
'max_tokens': 4000,
'is_think': 1,
'web_label': 0,
'stream_label': 0
})
data.append({
'stream_selected': 0,
'label': 'gpt-5-nano',
'value': 'gpt-5-nano',
'wechat_selected': 0,
'wechat_label': 0,
'selected': 0,
'max_tokens': 4000,
'is_think': 1,
'web_label': 0,
'stream_label': 0
})
data.append({
'stream_selected': 0,
'label': 'gpt-5-mini',
'value': 'gpt-5-mini',
'wechat_selected': 0,
'wechat_label': 0,
'selected': 0,
'max_tokens': 4000,
'is_think': 1,
'web_label': 0,
'stream_label': 0
})
data.append({
'stream_selected': 0,
'label': 'gpt-4.1',
'value': 'gpt-4.1',
'wechat_selected': 0,
'wechat_label': 0,
'selected': 0,
'max_tokens': 4000,
'is_think': 0,
'web_label': 0,
'stream_label': 0
})
data.append({
'stream_selected': 0,
'label': 'gpt-4.1-mini',
'value': 'gpt-4.1-mini',
'wechat_selected': 0,
'wechat_label': 0,
'selected': 0,
'max_tokens': 4000,
'is_think': 0,
'web_label': 0,
'stream_label': 0
})
data.append({
'stream_selected': 0,
'label': 'gpt-4.1-nano',
'value': 'gpt-4.1-nano',
'wechat_selected': 0,
'wechat_label': 0,
'selected': 0,
'max_tokens': 4000,
'is_think': 0,
'web_label': 0,
'stream_label': 0
})
data.append({
'stream_selected': 0,
'label': 'o3',
'value': 'o3',
'wechat_selected': 0,
'wechat_label': 0,
'selected': 0,
'max_tokens': 4000,
'is_think': 1,
'web_label': 0,
'stream_label': 0
})
# 3. 一次性把整个 data 写回去
result = collection.update_one(
{"name": "txt2txt_config"},
{"$set": {"data": data}}
)
print(f"matched={result.matched_count}, modified={result.modified_count}")
query = {"name": "txt2txt_config"}
projection = {"_id": 0, "data": 1}
doc = collection.find_one(query, projection)
if doc:
data_value = doc.get("data")
print(data_value)
else:
print("未找到 name 等于 txt2txt_config 的记录")
# 查询单条文档
# doc = collection.find_one(query, projection)
# db = col.database # 或者直接用 client["dashboard"]
# # 列出所有集合名
# collections = db.list_collection_names()
# print("当前 database 下的集合:", collections)
# ['mp_collection', 'system.profile', 'mtxx_odz_aimr_im_chat_order_label_aggregate', 'xx_expose_history', 'aibeauty_trigger', 'mtxx_odz_aimr_im_chat_order', 'my_music_history', 'aibeauty_data_beta', 'my_music_history_count14', 'xx_area_mapping', 'aibeauty_trigger_beta', 'aibeauty_feedback', 'counters', 'xx_music_history', 'aibeauty_directive_beta', 'gd_history', 'message_spark_list_beta', 'my_expose', 'aibeauty_directive', 'xx_material_history', 'message_tongyi_list', 'aibeauty_im_msg', 'xx_formula_save_top100', 'aibeauty_title_stat', 'aibeauty_data', 'config', 'message_wenxin_list_beta', 'im_chat_msg_type', 'mp_neg_feedback', 'my_click', 'my_material_use_info', 'message_list_beta', 'message_pangu_list', 'aibeauty_data_history', 'my_search_history', 'mp_live', 'aibeauty_feedback_beta', 'aibeauty_top_data', 'message_wenxin_list', 'mp_expose', 'aibeauty_title_beta', 'aibeauty_data_history_beta', 'mtxx_odz_aimr_im_chat_order_label', 'related_history', 'xx_new_user', 'mht_rec_path', 'xx_feed_count', 'sdk_adz_aigc_chatgpt_info', 'aibeauty_top_data_gid_room_id', 'video_4k_transcoder', 'my_material_info', 'xx_music_material_category', 'mp_click', 'my_banner_history', 'webui_task_beta', 'config_beta', 'mht_dynamic_info', 'aibeauty_top_data_prompt_roomlist', 'my_search_history_count14', 'my_material_info_30', 'webui_record_beta', 'my_material_history', 'message_list', 'my_tmpl_history', 'aibeauty_title_stat_beta', 'message_pangu_list_beta', 'xx_dislike', 'my_music_history_count30', 'my_recommend_view', 'nlp_timeliness', 'blackflow_history', 'aibeauty_title', 'aibeauty_top_data_beta', 'message_spark_list', 'message_tongyi_list_beta', 'click_history']