-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
移除某个时间点之后提出的问题, 以及它们的答案. 在程序出问题时使用 | ||
""" | ||
|
||
from datetime import datetime | ||
|
||
import pymongo | ||
|
||
t = datetime(2016,3,11,18,0,0) | ||
|
||
db = pymongo.MongoClient('127.0.0.1', 27017).zhihu_data | ||
q_colls = ["19550517_q", "19551147_q", "19561087_q", "19553298_q"] | ||
|
||
for q_coll in q_colls: | ||
coll = db.get_collection(q_coll) | ||
acoll = db.get_collection(q_coll[:-1] + 'a') | ||
for qdoc in coll.find(): | ||
if qdoc['time'] < t: | ||
result = coll.delete_one({'qid': qdoc['qid']}) | ||
assert result.deleted_count == 1 | ||
print("question %s removed" % qdoc['qid']) | ||
result = acoll.delete_many({'qid': qdoc['qid']}) | ||
print("%d answers removed" % result.deleted_count) |