sin30 commited on
Commit
9e8747f
·
verified ·
1 Parent(s): 872e627

Upload mongo.py

Browse files
Files changed (1) hide show
  1. mongo.py +30 -4
mongo.py CHANGED
@@ -13,20 +13,46 @@ def get_mongo_col(col="config_beta"):
13
  # 拿到 collection 对象
14
  collection = get_mongo_col() # 默认 col="config_beta"
15
 
16
- service_name = "us.anthropic.claude-3-7-sonnet-20250219-v1:0"
17
- service_data = {
 
 
 
 
 
 
 
 
 
 
18
  "completion_price": 0.015,
19
  "prompt_price": 0.003,
20
  "currency": "$"
21
  }
22
 
 
 
 
23
  result = collection.update_one(
24
  {"name": "txt2txt_price_config"},
25
- {"$set": {f"data.{service_name}": service_data}}
26
  )
27
-
28
  print(f"matched={result.matched_count}, modified={result.modified_count}")
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  query = {"name": "txt2txt_price_config"}
32
  projection = {"_id": 0, "data": 1}
 
13
  # 拿到 collection 对象
14
  collection = get_mongo_col() # 默认 col="config_beta"
15
 
16
+
17
+ doc = collection.find_one(
18
+ {"name": "txt2txt_price_config"},
19
+ {"_id": 0, "data": 1}
20
+ )
21
+ if not doc:
22
+ raise RuntimeError("找不到配置 document")
23
+
24
+ data = doc["data"]
25
+
26
+ # 2. 在本地 dict 里插入/修改
27
+ data["us.anthropic.claude-3-7-sonnet-20250219-v1:0"] = {
28
  "completion_price": 0.015,
29
  "prompt_price": 0.003,
30
  "currency": "$"
31
  }
32
 
33
+ del data["us"]
34
+
35
+ # 3. 一次性把整个 data 写回去
36
  result = collection.update_one(
37
  {"name": "txt2txt_price_config"},
38
+ {"$set": {"data": data}}
39
  )
 
40
  print(f"matched={result.matched_count}, modified={result.modified_count}")
41
 
42
+ # service_name = "us.anthropic.claude-3-7-sonnet-20250219-v1:0"
43
+ # service_data = {
44
+ # "completion_price": 0.015,
45
+ # "prompt_price": 0.003,
46
+ # "currency": "$"
47
+ # }
48
+
49
+ # result = collection.update_one(
50
+ # {"name": "txt2txt_price_config"},
51
+ # {"$set": {f"data.{service_name}": service_data}}
52
+ # )
53
+
54
+ # print(f"matched={result.matched_count}, modified={result.modified_count}")
55
+
56
 
57
  query = {"name": "txt2txt_price_config"}
58
  projection = {"_id": 0, "data": 1}