Administrator
3 天以前 5f034f7a6733b03e0d08d7920ec6de1b1517c421
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
mongodb 数据管理
"""
import pymongo
 
mongo_host = "127.0.0.1"
mongo_port = 27017
 
 
def _getdb():
    client = pymongo.MongoClient(host=mongo_host, port=27017)
    db = client.gp
    return db
 
 
def save(dn_name, datas):
    try:
        db = _getdb()
        collections = db[dn_name]
        for data in datas:
            collections.delete_one({"_id": data["_id"]})
            collections.insert_one(data)
    except:
        pass
 
 
def save_one(dn_name, data):
    try:
        db = _getdb()
        collections = db[dn_name]
        collections.delete_one({"_id": data["_id"]})
        collections.insert_one(data)
    except:
        pass
 
 
def find(dn_name, where_dict):
    try:
        db = _getdb()
        collections = db[dn_name]
        result = collections.find(where_dict)
        # print(result)
        return result
    except:
        pass
 
 
def count(dn_name, where_dict):
    try:
        db = _getdb()
        collections = db[dn_name]
        result = collections.count_documents(where_dict)
        # print(result)
        return result
    except:
        pass
 
 
if __name__ == '__main__':
 
    result = find("ths-industry-codes", {'$or': [{'_id': '300007'}, {'_id': '300008'}]})
    for a in result:
        print(a)