forked from qiyeboy/SpiderBook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
8.3.py
41 lines (30 loc) · 916 Bytes
/
8.3.py
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
#coding:utf-8
import datetime
import pymongo
client = pymongo.MongoClient('mongodb://localhost:27017/')
db = client.papers
collection = db.books
book = {"author": "Mike",
"text": "My first book!",
"tags": ["爬虫", "python", "网络"],
"date": datetime.datetime.utcnow()
}
book_id= collection .insert(book)
books = [{"author": "Mike",
"text": "My first book!",
"tags": ["爬虫", "python", "网络"],
"date": datetime.datetime.utcnow()
},{"author": "qiye",
"text": "My sec book!",
"tags": ["hack", "python", "渗透"],
"date": datetime.datetime.utcnow()
}]
books_id = collection.insert(books)
collection.find_one({"author": "qiye"})
for book in collection.find():
print book
for book in collection.find({"author": "qiye"}):
print book
collection.find({"author": "qiye"}).count()
collection.update({"author": "qiye"},{"$set":{"text":"python book"}})
collection.remove({"author": "qiye"})