Upload mongo.py
Browse files
mongo.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pymongo
|
| 2 |
+
|
| 3 |
+
def get_mongo_col(col="config_beta"):
|
| 4 |
+
"""
|
| 5 |
+
获取操作mongo集合
|
| 6 |
+
"""
|
| 7 |
+
mongo_3012 = "mongodb://dashboard:9qRV71M%25Trx1CI@m3012.hw.mongos.m.com:3012/dashboard?authSource=dashboard"
|
| 8 |
+
client = pymongo.MongoClient(mongo_3012, maxPoolSize=500)
|
| 9 |
+
db = client["dashboard"]
|
| 10 |
+
col = db[col] # data_package(7234543961263854561) goods_feature("7234800834201014260")
|
| 11 |
+
return col
|
| 12 |
+
|
| 13 |
+
# 拿到 collection 对象
|
| 14 |
+
col = get_mongo_col() # 默认 col="config_beta"
|
| 15 |
+
|
| 16 |
+
db = col.database # 或者直接用 client["dashboard"]
|
| 17 |
+
|
| 18 |
+
# 列出所有集合名
|
| 19 |
+
collections = db.list_collection_names()
|
| 20 |
+
print("当前 database 下的集合:", collections)
|