indexが増えてしまい、意図しないindexが先に当たって遅くなることがあったので、hintを与えてindexを指定する必要が出てきた。
データ構造を変えられないのでこれからお世話になるであろう為メモ
c⌒っ゚д゚)っφ メモメモ...
spec = {
'user_id': {'$in': user_id_list},
'type': 'a',
'status': 0,
'at': {'$lte': datetime.datetime.utcnow()}
}
cursor = db.collection.find(spec)
cursor.sort('at', -1).limit(500)
cursor.hint([
('at', pymongo.DESCENDING),
('user_id', pymongo.ASCENDING),
('type', pymongo.ASCENDING),
('status', pymongo.ASCENDING),
('_id', pymongo.DESCENDING),
])