にMongoDBからリストを取得し、それを並べ替え:リストで検索する方法を
results = list(db1.zaklad.find({"name": "cola", "stav": '+'}))
print(a)
sorted_results = sorted(results, key=itemgetter('weight'), reverse=True)
Imが取得:[{'_id': ObjectId('5a13a8c396fb3488bb6a0648'), 'name': 'cola', 'weight': '3', 'url': 'goo.gl/2BgLmm', 'stav': '+', 'time_exp': datetime.datetime(2017, 11, 17, 23, 37, 31, 946000)}, {'_id': ObjectId('5a13a8bc96fb3488bb6a0647'), 'name': 'cola', 'weight': '2', 'url': 'goo.gl/2BgLmm', 'stav': '+', 'time_exp': datetime.datetime(2017, 11, 17, 23, 37, 31, 946000)}, {'_id': ObjectId('5a13a8ca96fb3488bb6a0649'), 'name': 'cola', 'weight': '2', 'url': 'goo.gl/2BgLmm', 'stav': '+', 'time_exp': datetime.datetime(2017, 11, 17, 23, 37, 31, 946000)}
このリストから、私は例から、上記(すべての非繰り返し重みを取得したい:3, 2
)。
このリストの検索方法は? dict(enumerate(results))
で辞書をやり直すのは良いですか?あなたの助けのための
Thxを