MCPcopy Create free account
hub / github.com/ZiniuLu/Python-100-Days / main

Function main

Day66-75/code/example07.py:5–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3
4# BSON - Binary JSON - dict
5def main():
6 # client = pymongo.MongoClient('mongodb://120.77.222.217:27017')
7 client = pymongo.MongoClient(host='120.77.222.217', port=27017)
8 db = client.zhihu
9 pages_cache = db.webpages
10 """
11 pages_cache.insert_many([
12 {'_id': 1, 'url': 'http://www.baidu.com', 'content': 'shit'},
13 {'_id': 2, 'url': 'http://www.qq.com', 'content': 'another shit'},
14 {'_id': 3, 'url': 'http://www.qfedu.com', 'content': 'biggest shit'}
15 ])
16
17 print(pages_cache.update({'_id': 5}, {'$set': {'content': 'hello, world!'}}, upsert=True))
18 # page_id = pages_cache.insert_one({'url': 'http://www.baidu.com', 'content': '<html></html>'})
19 # print(page_id.inserted_id)
20 # print(pages_cache.remove({'url': 'http://www.baidu.com'}))
21 print(pages_cache.find().count())
22 for doc in pages_cache.find().sort('_id'):
23 print(doc)
24 """
25 pages_cache.insert_one({
26 'url': 'http://www.baidu.com',
27 'content': 'bull shit!',
28 'owner': {
29 'name': 'Lee Yanhong',
30 'age': 50,
31 'idcard': '110220196804091203'
32 }
33 })
34
35
36if __name__ == '__main__':

Callers 1

example07.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected