Specify hint with pymongo

Since the index increased and the unintended index hit first and slowed down, it became necessary to give hint and specify the index. I can't change the data structure, so I'll take care of it from now on. c⌒ ゚ д ゚) tsu φ Memo Memo ...

        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),
        ])

Recommended Posts

Specify hint with pymongo
Distinct with pymongo
mongodb access with pymongo
Regular expression with pymongo
Specify version with conda install
Specify python version with virtualenv
python memo --Specify options with getopt
Specify options when running flake8 with flycheck