Is there a faster way to convert a pymongo Cursor object to list?

Viewed 13

I'm gonna to retrive data from mongodb and convert it to list as below :

    for vehicle in vehicles:
    vehicle_mongo = vehicle_collection.find({'frame_uuid': vehicle.frames_identifier}, needed_fields)
    yield {
        'vehicle_make': getattr(vehicle, 'vehicle_make', ''),
        'vehicle_color': getattr(vehicle, 'vehicle_color', ''),
        'vehicle_type': getattr(vehicle, 'vehicle_type', ''),
        'vehicle_model': getattr(vehicle, 'vehicle_model', ''),
        'plate_number': getattr(vehicle, 'plate_number', ''),
        'frames_identifier': getattr(vehicle, 'frames_identifier', ''),
        'frames': list(vehicle_mongo)
    }

this line 'frames': list(vehicle_mongo) will decrease my speed about 1000% and it's so slow! Is there a faster way to convert a pymongo Cursor object to list? Thanks!

0 Answers
Related