我也推荐神奇的dex: https://github.com/mongolab/dex
7 | 10 |索引字段不够(需要复合索引)
11 |xx/models.py 143-146行
12 | statuses = list(coll.find(
13 | {"is_update": False},
14 | {"uid": 1}
15 | ).sort('date', -1).limit(200))
16 |
17 | > db.status_5008fe57b3158aa4709ecd8f_201311.getIndexes()
18 | [
19 | {
20 | "v" : 1,
21 | "key" : {
22 | "_id" : 1
23 | },
24 | "ns" : "dongwm.status_5008fe57b3158aa4709ecd8f_201311",
25 | "name" : "_id_"
26 | },
27 | {
28 | "v" : 1,
29 | "key" : {
30 | "date" : -1
31 | },
32 | "ns" : "dongwm.status_5008fe57b3158aa4709ecd8f_201311",
33 | "name" : "cdate_-1"
34 | },
35 | {
36 | "v" : 1,
37 | "key" : {
38 | "idate" : -1
39 | },
40 | "ns" : "dongwm.status_5008fe57b3158aa4709ecd8f_201311",
41 | "name" : "idate_-1"
42 | }
43 | ]
44 |
45 |
46 | db["status_5008fe57b3158aa4709ecd8f_201311"].ensureIndex({"is_update": 1, "date": 1}, {"background": true})
47 |
48 | 没有索引
49 |xx/tasks.py 551-564行
50 | pre_date = update_date - timedelta(hours=1)
51 | pre_infcoll = s_db["inf_%s_%s" % (
52 | key["_id"], pre_date.strftime("%Y%m")
53 | )]
54 | pre_ho = {}
55 | pre_inf = (
56 | pre_infcoll.find_one({
57 | "day": update_date.replace(
58 | hour=0,
59 | minute=0,
60 | second=0,
61 | microsecond=0
62 | )
63 | }) or {}).get(str(pre_date.hour), [])
64 |
65 |
66 | > db.dongwm.influence_51ee2552fb0dd8d290a7749a_201311.getIndexes()
67 | [ ]
68 |
69 |
70 | db["inf_51ee2552fb0dd8d290a7749a_201311"].ensureIndex({"day": 1}, {"background": true})
71 |
72 | 索引顺序问题
74 |xx/models.py 1110-1119行
75 | def get_o_s(uid, date):
76 | return list(db.st.find(
77 | {
78 | 'user_id': uid,
79 | 'created_at': {'$gte': date},
80 | 'rs': 0
81 | },
82 | {'rsince_timestamp': 1, 'csince_timestamp': 1, 'last_cid': 1}
83 | ))
84 |
85 |
86 | > db.status.getIndexes()
87 | [
88 | {
89 | "v" : 1,
90 | "key" : {
91 | "_id" : 1
92 | },
93 | "ns" : "dongwm.status",
94 | "name" : "_id_"
95 | }
96 | ]
97 |
98 |
99 | db["status"].ensureIndex({"user_id": 1, "rs": 1, "created_at": 1}, {"background": true})
100 |
101 |
102 |
113 |