mongo result found by array not sorted as orginal array

sourcelist = []
for c in blocklist:
    oids = c.get('content', []) #orginal array
    sorted_list = list(db_source.find({'_id':{'$in':oids}}))    #result, has been re-sorted not as aspected
    sorted_key = dict(zip(oids, [x for x in range(len(oids))])) #construct a referal array
    #sourcelist order resort
    for cc in sorted_list:
        cc['order'] = sorted_key.get(cc.get('_id')) #add an additional field
    sourcelist.append({
        'name': c.get('name'),
        'content': [to_one_str_source(i) for i in sorted(sorted_list, key=lambda k:k['order'])] #sort by additional field
    })

你可能感兴趣的:(mongo result found by array not sorted as orginal array)